Cleanup Convert-HexToAnsiiEscape

This commit is contained in:
elkowar 2021-10-28 14:36:51 +02:00
parent d88104d0f7
commit dd285ef4ba
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F

View file

@ -19,11 +19,8 @@ function Convert-HexToAnsiiEscape
{ {
param ([Parameter(Mandatory)] [string]$hex) param ([Parameter(Mandatory)] [string]$hex)
$nohash = $hex.substring(1) $nohash = $hex.substring(1)
$rgb = $nohash -split '(..)' -ne '' $rgb = $nohash -split '(..)' -ne '' | ForEach-Object { [Convert]::ToInt64($_, 16) }
$r = [Convert]::ToInt64($rgb[0], 16) [char]27 + "$ansi_escape[38;2;{0};{1};{2}m" -f $rgb[0], $rgb[1],$rgb[2]
$g = [Convert]::ToInt64($rgb[1], 16)
$b = [Convert]::ToInt64($rgb[2], 16)
[char]27 + "$ansi_escape[38;2;{0};{1};{2}m" -f $r, $g, $b
} }
$Colors = @{ $Colors = @{