Created
June 14, 2018 07:41
-
-
Save wgross/cc7a01cb040e86e2b67646932345f48a to your computer and use it in GitHub Desktop.
Format text with ansi sequences in powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/bozho/AnsiColorOut/blob/master/AnsiColorOut/Console.cs | |
# https://stackoverflow.com/questions/4842424/list-of-ansi-color-escape-sequences | |
$esc=[char]0x001b | |
filter esc { | |
param( | |
[ValidateSet("underline","italic")] | |
[string[]]$Format | |
) | |
$text = $PSItem | |
$escSequence = "$esc[" | |
$Format|ForEach-Object -Process { | |
switch($_) { | |
"underline" { | |
$escSequence += "4;" | |
} | |
"italic" { | |
$escSequence += "3;" | |
} | |
} | |
} | |
"$($escSequence)m$([string]$text)$esc[0m" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment