Skip to content

Commit 72572fc

Browse files
committed
Use strings as ConsoleColor if no System.Drawing
1 parent 99f130d commit 72572fc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/AnsiUtils.ps1

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ $ColorTranslatorType = 'System.Drawing.ColorTranslator' -as [Type]
2525
$ColorType = 'System.Drawing.Color' -as [Type]
2626

2727
function Get-VirtualTerminalSequence ($color, [int]$offset = 0) {
28-
if (($color -is [ConsoleColor]) -and ($color -ge 0) -and ($color -le 15)) {
29-
return "${AnsiEscape}$($ConsoleColorToAnsi[$color] + $offset)m"
30-
}
3128
if ($color -is [byte]) {
3229
return "${AnsiEscape}$(38 + $offset);5;${color}m"
3330
}
34-
if ($ColorTranslatorType -and ($color -is [String])) {
31+
if ($color -is [String]) {
3532
try {
36-
$color = $ColorTranslatorType::FromHtml($color)
33+
if ($ColorTranslatorType) {
34+
$color = $ColorTranslatorType::FromHtml($color)
35+
}
36+
else {
37+
$color = [ConsoleColor]$color
38+
}
3739
}
3840
catch {
3941
Write-Debug $_
@@ -42,6 +44,9 @@ function Get-VirtualTerminalSequence ($color, [int]$offset = 0) {
4244
if ($ColorType -and ($color -is $ColorType)) {
4345
return "${AnsiEscape}$(38 + $offset);2;$($color.R);$($color.G);$($color.B)m"
4446
}
47+
if (($color -is [ConsoleColor]) -and ($color -ge 0) -and ($color -le 15)) {
48+
return "${AnsiEscape}$($ConsoleColorToAnsi[$color] + $offset)m"
49+
}
4550
return "${AnsiEscape}$($AnsiDefaultColor + $offset)m"
4651
}
4752

0 commit comments

Comments
 (0)