0.1.0/Theme.WindowsConsole.psm1

using namespace PoshCode.Pansies
#Region '.\Public\Get-WindowsConsoleTheme.ps1' 0
#using namespace PoshCode.Pansies

function Get-WindowsConsoleTheme {
    <#
        .SYNOPSIS
            Get the current theme from the Windows Console
    #>

    [CmdletBinding()]
    param(
        # The name for the theme
        [string]$Name = "EzTheme",

        # If set, get the default theme from Windows. Otherwise return the current theme
        [Switch]$Default
    )

    end {
        $Palette = if ($Default)
        {
            [WindowsConsoleHelper]::GetDefaultConsolePalette($true);
        }
        else
        {
            [WindowsConsoleHelper]::GetCurrentConsolePalette($true);
        }

        [PSCustomObject]@{
            PSTypeName      = "Terminal.ColorScheme"
            name            = "$Name"
            # The windows API uses a different palette order than everyone else
            black           = $Palette[0]
            blue            = $Palette[1]
            green           = $Palette[2]
            cyan            = $Palette[3]
            red             = $Palette[4]
            purple          = $Palette[5]
            yellow          = $Palette[6]
            white           = $Palette[7]
            brightBlack     = $Palette[8]
            brightBlue      = $Palette[9]
            brightGreen     = $Palette[10]
            brightCyan      = $Palette[11]
            brightRed       = $Palette[12]
            brightPurple    = $Palette[13]
            brightYellow    = $Palette[14]
            brightWhite     = $Palette[15]

            foreground      = $Palette[16]
            background      = $Palette[17]

            popupForeground = $Palette[18]
            popupBackground = $Palette[19]
        }
    }
}
#EndRegion '.\Public\Get-WindowsConsoleTheme.ps1' 56
#Region '.\Public\Set-WindowsConsoleTheme.ps1' 0
#using namespace PoshCode.Pansies

function Set-WindowsConsoleTheme {
    <#
        .SYNOPSIS
            Set the theme for the Windows Console
            Has parameters for each color, including foreground and background
    #>

    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipelineByPropertyName)]
        [string]$Name = "EzTheme",

        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$background = "#0C0C0C",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$foreground = "#CCCCCC",

        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$black = "#0C0C0C",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$red = "#C50F1F",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$green = "#13A10E",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$yellow = "#C19C00",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$blue = "#0037DA",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$purple = "#881798",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$cyan = "#3A96DD",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$white = "#CCCCCC",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightBlack = "#767676",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightRed = "#E74856",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightGreen = "#16C60C",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightYellow = "#F9F1A5",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightBlue = "#3B78FF",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightPurple = "#B4009E",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightCyan = "#61D6D6",
        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$brightWhite = "#F2F2F2",

        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$PopupBackground = "#881798",

        [Parameter(ValueFromPipelineByPropertyName)]
        [RgbColor]$PopupForeground = "#F2F2F2",

        # Set the default Windows Console theme as well as the current theme
        [switch]$Default
    )

    process {
        # The windows API uses a different palette order
        [RgbColor[]]$Palette = @(
            $Black
            $Blue
            $Green
            $Cyan
            $Red
            $Purple
            $Yellow
            $BrightBlack
            $White
            $BrightBlue
            $BrightGreen
            $BrightCyan
            $BrightRed
            $BrightPurple
            $BrightYellow
            $BrightWhite
        )

        if ($PSBoundParameters.ContainsKey("Foreground")) {
            $Palette += $Foreground
        } else {
            $Palette += $White
        }

        if ($PSBoundParameters.ContainsKey("Background")) {
            $Palette += $Background
        } else {
            $Palette += $Black
        }

        if ($PSBoundParameters.ContainsKey("PopupForeground")) {
            $Palette += $PopupForeground
        } else {
            $Palette += $BrightWhite
        }

        if ($PSBoundParameters.ContainsKey("PopupBackground")) {
            $Palette += $PopupBackground
        } else {
            $Palette += $Purple
        }

        if ($Default) {
            [WindowsConsoleHelper]::SetDefaultConsolePalette($Palette)
        }
        [WindowsConsoleHelper]::SetCurrentConsolePalette($Palette)
    }
}
#EndRegion '.\Public\Set-WindowsConsoleTheme.ps1' 113