Skip to content

Instantly share code, notes, and snippets.

@midnightfreddie
Last active November 7, 2017 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save midnightfreddie/25efaf14114b37d30061169e04080bca to your computer and use it in GitHub Desktop.
Save midnightfreddie/25efaf14114b37d30061169e04080bca to your computer and use it in GitHub Desktop.
# PowerShell 5 and above
Enum MyConColor {
Black
Red
Green
Yellow
Blue
Magenta
Cyan
White
}
# Pre-PowerShell-5 uses C# for enums
#Add-Type -TypeDefinition @"
# public enum MyConColor {
# Black,
# Red,
# Green,
# Yellow,
# Blue,
# Magenta,
# Cyan,
# White
# }
#"@
# "Strong black" is gray
function Get-ConColors {
param (
[Parameter(Position=1,Mandatory=$true)]
[String]$Text,
[MyConColor]$ForegroundColor = [MyConColor]::White,
[MyConColor]$BackgroundColor = [MyConColor]::Blue,
[switch]$ForegroundStrong,
[switch]$BackgroundStrong
)
$ConsoleTemplate = [char]27 + '[{0}m'
$FG = 30 + [int]$ForegroundColor
if ($ForegroundStrong) { $FG += 60 }
$BG = 40 + [int]$BackgroundColor
if ($BackgroundStrong) { $BG += 60 }
Write-Output (
$ConsoleTemplate -f $FG +
$ConsoleTemplate -f $BG +
$Text +
$ConsoleTemplate -f 0
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment