Skip to content

Instantly share code, notes, and snippets.

@wgross
Created June 14, 2018 07:41
Show Gist options
  • Save wgross/cc7a01cb040e86e2b67646932345f48a to your computer and use it in GitHub Desktop.
Save wgross/cc7a01cb040e86e2b67646932345f48a to your computer and use it in GitHub Desktop.
Format text with ansi sequences in powershell
# 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