-
-
Notifications
You must be signed in to change notification settings - Fork 811
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Settings & Write-GitStatus function #513
Changes from all commits
a7b01c5
7460daf
98c61bb
b28513c
4d8e08c
8fcfc21
7fb0d6d
8dee3e7
71a085a
fa2b05b
facc87d
5120624
88312b2
b656d1e
db734a6
b7b58bc
53cb658
a3a4ffe
2af60e0
6235734
9f9a649
635c113
041c286
2831c0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,29 +24,60 @@ $AnsiEscape = [char]27 + "[" | |
$ColorTranslatorType = 'System.Drawing.ColorTranslator' -as [Type] | ||
$ColorType = 'System.Drawing.Color' -as [Type] | ||
|
||
function EscapseAnsiString([string]$AnsiString) { | ||
if ($PSVersionTable.PSVersion.Major -ge 6) { | ||
$res = $AnsiString -replace "$([char]27)", '`e' | ||
} | ||
else { | ||
$res = $AnsiString -replace "$([char]27)", '$([char]27)' | ||
} | ||
|
||
$res | ||
} | ||
|
||
function Test-VirtualTerminalSequece([psobject]$Object) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a type declaration to make clear this function accepts any type. |
||
if ($global:GitPromptSettings.AnsiConsole -and ($Object -is [string])) { | ||
return $Object.Contains($AnsiEscape) | ||
} | ||
else { | ||
return $false | ||
} | ||
} | ||
|
||
function Get-VirtualTerminalSequence ($color, [int]$offset = 0) { | ||
if ($color -is [byte]) { | ||
return "${AnsiEscape}$(38 + $offset);5;${color}m" | ||
} | ||
|
||
if ($color -is [int]) { | ||
$r = ($color -shr 16) -band 0xff | ||
$g = ($color -shr 8) -band 0xff | ||
$b = $color -band 0xff | ||
return "${AnsiEscape}$(38 + $offset);2;${r};${g};${b}m" | ||
} | ||
|
||
if ($color -is [String]) { | ||
try { | ||
if ($ColorTranslatorType) { | ||
$color = $ColorTranslatorType::FromHtml($color) | ||
if ($null -ne ($color -as [System.ConsoleColor])) { | ||
$color = [System.ConsoleColor]$color | ||
} | ||
else { | ||
$color = [ConsoleColor]$color | ||
elseif ($ColorTranslatorType) { | ||
$color = $ColorTranslatorType::FromHtml($color) | ||
} | ||
} | ||
catch { | ||
Write-Debug $_ | ||
} | ||
} | ||
|
||
if ($ColorType -and ($color -is $ColorType)) { | ||
return "${AnsiEscape}$(38 + $offset);2;$($color.R);$($color.G);$($color.B)m" | ||
} | ||
if (($color -is [ConsoleColor]) -and ($color -ge 0) -and ($color -le 15)) { | ||
|
||
if (($color -is [System.ConsoleColor]) -and ($color -ge 0) -and ($color -le 15)) { | ||
return "${AnsiEscape}$($ConsoleColorToAnsi[$color] + $offset)m" | ||
} | ||
|
||
return "${AnsiEscape}$($AnsiDefaultColor + $offset)m" | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, this function is used in the
ToString()
functions to display the original ANSI seq e.g.: