Created
January 12, 2022 10:29
-
-
Save jhoneill/5912cd1ecac551fc3ada13df599f2f67 to your computer and use it in GitHub Desktop.
This file contains 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
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- ******************************************************************* | |
Copyright (c) James O'Neill 2022 - Shared under the MIT License https://mit-license.org/ | |
Allows [consoleColor] to be used like this | |
ps > [ConsoleColor]::Red.Foreground("This is red") | |
ps > [ConsoleColor]::DarkYellow.Background([ConsoleColor]::red.Foreground("This is red on darkyellow")) | |
Or in a function where | |
param ( [ConsoleColor]$NewItemColor = "Green") | |
... | |
foreach ($f in $file) { | |
if ($f.LastWriteTime -lt [datetime]::Today) {$f.name} | |
else {$NewItemColor.Foreground($f.name)} | |
} | |
******************************************************************** --> | |
<Types> | |
<Type> | |
<Name>System.ConsoleColor</Name> | |
<Members> | |
<ScriptMethod> | |
<Name>Foreground</Name> | |
<Script> | |
param ($Text) | |
if ($psstyle) { | |
return @{ | |
'Black' = $PSStyle.Foreground.Black | |
'DarkBlue' = $PSStyle.Foreground.Blue | |
'DarkGreen' = $PSStyle.Foreground.Green | |
'DarkCyan' = $PSStyle.Foreground.Cyan | |
'DarkRed' = $PSStyle.Foreground.Red | |
'DarkMagenta' = $PSStyle.Foreground.Magenta | |
'DarkYellow' = $PSStyle.Foreground.Yellow | |
'Gray' = $PSStyle.Foreground.White | |
'DarkGray' = $PSStyle.Foreground.BrightBlack | |
'Blue' = $PSStyle.Foreground.BrightBlue | |
'Green' = $PSStyle.Foreground.BrightGreen | |
'Cyan' = $PSStyle.Foreground.BrightCyan | |
'Red' = $PSStyle.Foreground.BrightRed | |
'Magenta' = $PSStyle.Foreground.BrightMagenta | |
'Yellow' = $PSStyle.Foreground.BrightYellow | |
'White' = $PSStyle.Foreground.BrightWhite | |
}[$this.ToString()] + $Text + $psstyle.Reset | |
} | |
else {return @{ | |
'Black' = "$([char]27)[30m" | |
'DarkBlue' = "$([char]27)[34m" | |
'DarkGreen' = "$([char]27)[32m" | |
'DarkCyan' = "$([char]27)[36m" | |
'DarkRed' = "$([char]27)[31m" | |
'DarkMagenta' = "$([char]27)[35m" | |
'DarkYellow' = "$([char]27)[33m" | |
'Gray' = "$([char]27)[37m" | |
'DarkGray' = "$([char]27)[90m" | |
'Blue' = "$([char]27)[94m" | |
'Green' = "$([char]27)[92m" | |
'Cyan' = "$([char]27)[96m" | |
'Red' = "$([char]27)[91m" | |
'Magenta' = "$([char]27)[95m" | |
'Yellow' = "$([char]27)[93m" | |
'White' = "$([char]27)[97m" | |
}[$this.ToString()] + $Text + "$([char]27)[0m" | |
} | |
</Script> | |
</ScriptMethod> | |
<ScriptMethod> | |
<Name>Background</Name> | |
<Script> | |
param ($Text) | |
if ($psstyle) { | |
return @{ | |
'Black' = $PSStyle.Background.Black | |
'DarkBlue' = $PSStyle.Background.Blue | |
'DarkGreen' = $PSStyle.Background.Green | |
'DarkCyan' = $PSStyle.Background.Cyan | |
'DarkRed' = $PSStyle.Background.Red | |
'DarkMagenta' = $PSStyle.Background.Magenta | |
'DarkYellow' = $PSStyle.Background.Yellow | |
'Gray' = $PSStyle.Background.White | |
'DarkGray' = $PSStyle.Background.BrightBlack | |
'Blue' = $PSStyle.Background.BrightBlue | |
'Green' = $PSStyle.Background.BrightGreen | |
'Cyan' = $PSStyle.Background.BrightCyan | |
'Red' = $PSStyle.Background.BrightRed | |
'Magenta' = $PSStyle.Background.BrightMagenta | |
'Yellow' = $PSStyle.Background.BrightYellow | |
'White' = $PSStyle.Background.BrightWhite | |
}[$this.ToString()] + $Text + $psstyle.Reset | |
} | |
else {return @{ | |
'Black' = "$([char]27)[40m" | |
'DarkBlue' = "$([char]27)[44m" | |
'DarkGreen' = "$([char]27)[42m" | |
'DarkCyan' = "$([char]27)[46m" | |
'DarkRed' = "$([char]27)[41m" | |
'DarkMagenta' = "$([char]27)[45m" | |
'DarkYellow' = "$([char]27)[43m" | |
'Gray' = "$([char]27)[47m" | |
'DarkGray' = "$([char]27)[100m" | |
'Blue' = "$([char]27)[104m" | |
'Green' = "$([char]27)[102m" | |
'Cyan' = "$([char]27)[106m" | |
'Red' = "$([char]27)[101m" | |
'Magenta' = "$([char]27)[105m" | |
'Yellow' = "$([char]27)[103m" | |
'White' = "$([char]27)[107m" | |
}[$this.ToString()] + $Text + "$([char]27)[0m" | |
} | |
</Script> | |
</ScriptMethod> | |
</Members> | |
</Type> | |
</Types> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment