Skip to content

Commit

Permalink
fixup! Optimize ANSI escape lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlbyk committed Sep 19, 2016
1 parent 55ba9e2 commit c633f94
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions Utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ function Get-LocalOrParentPath($path) {

# Color codes from https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx
$ConsoleColorToAnsi = @(
00 # Black
04 # DarkBlue
02 # DarkGreen
06 # DarkCyan
01 # DarkRed
05 # DarkMagenta
03 # DarkYellow
07 # Gray
60 # DarkGray
64 # Blue
62 # Green
66 # Cyan
61 # Red
65 # Magenta
63 # Yellow
67 # White
30 # Black
34 # DarkBlue
32 # DarkGreen
36 # DarkCyan
31 # DarkRed
35 # DarkMagenta
33 # DarkYellow
37 # Gray
90 # DarkGray
94 # Blue
92 # Green
96 # Cyan
91 # Red
95 # Magenta
93 # Yellow
97 # White
)
Write-Host $ConsoleColorToAnsi.Length
$AnsiDefaultColor = [char]27 + "["
$AnsiEscape = [char]27 + "["

function Get-VirtualTerminalSequence ([ConsoleColor]$color, [int]$offset = 0) {
if (($color -lt 0) -or ($color -gt 15)) {
return "${AnsiEscape}$(39 + $offset)m"
return "${AnsiEscape}$($AnsiDefaultColor + $offset)m"
}
return "${AnsiEscape}$(30 + $offset + $ConsoleColorToAnsi[$color])m"
return "${AnsiEscape}$($ConsoleColorToAnsi[$color] + $offset)m"
}

function Get-ForegroundVirtualTerminalSequence($Color) {
Expand Down

0 comments on commit c633f94

Please sign in to comment.