forked from jdhitsolutions/PSScriptTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvert-HTMLtoANSI.ps1
More file actions
31 lines (29 loc) · 1003 Bytes
/
Convert-HTMLtoANSI.ps1
File metadata and controls
31 lines (29 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Function Convert-HtmlToAnsi {
[cmdletbinding()]
[OutputType("System.String")]
[alias("cha")]
Param(
[Parameter(
Position = 0,
Mandatory,
ValueFromPipeline,
HelpMessage = "Specify an HTML color code like #13A10E"
)]
[ValidatePattern('^#\w{6}$')]
[alias("code")]
[string]$HtmlCode
)
Begin {
Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)"
} #begin
Process {
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Converting $HTMLCode"
$code = [System.Drawing.ColorTranslator]::FromHtml($htmlCode)
Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] RGB = $($code.r),$($code.g),$($code.b)"
$ansi = '[38;2;{0};{1};{2}m' -f $code.R,$code.G,$code.B
$ansi
} #process
End {
Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)"
} #end
} #close Convert-HTMLtoANSI