Theme.PowerShell.psm1

using namespace PoshCode.Pansies
using namespace System.Management.Automation
#Region '.\Public\Get-PowerShellTheme.ps1' 0
#using namespace PoshCode.Pansies
#using namespace System.Management.Automation

function Get-PowerShellTheme {
    <#
        .SYNOPSIS
            Returns a hashtable of the _current_ values that can be splatted to Set-Theme
    #>

    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipeline)]
        [string]$ColorScheme
    )
    process {
        if ($Host.PrivateData.PSTypeNames[0] -ne 'Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy') {
            $ErrorMessage = 'PowerShell $Host.PrivateData is not the ConsoleHost+ConsoleColorProxy'
            $Exception = [PSInvalidOperationException]::new($ErrorMessage)
            $PSCmdlet.ThrowTerminatingError([ErrorRecord]::new($Exception, "Unsupported Host PrivateData", "InvalidData", $Host.PrivateData))
        }
        if ($RawUI = $Host.UI.RawUI) {
            $Result = $Host.PrivateData |
                Select-Object *Color |
                Add-Member -NotePropertyName Foreground -NotePropertyValue $RawUI.ForegroundColor -PassThru |
                Add-Member -NotePropertyName Background -NotePropertyValue $RawUI.BackgroundColor -PassThru

        } else {
            $Result = $Host.PrivateData |
                Select-Object *Color
        }
        $Result.PSTypeNames.Insert(0, "Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy")
        $Result
    }
}

#EndRegion '.\Public\Get-PowerShellTheme.ps1' 35
#Region '.\Public\Set-PowerShellTheme.ps1' 0
#using namespace PoshCode.Pansies

function Set-PowerShellTheme {
    <#
        .SYNOPSIS
            Set the color theme for PowerShell output
            Has parameters for each color, including the default foreground and background, plus the new ErrorAccentColor and FormatAccentColor
    #>

    [CmdletBinding()]
    param(
        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$ForegroundColor = "White",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$BackgroundColor = "Black",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$FormatAccentColor = "Green",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$ErrorAccentColor = "Yellow",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$ErrorForegroundColor = "Red",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$ErrorBackgroundColor = "Black",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$WarningForegroundColor = "Yellow",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$WarningBackgroundColor = "Black",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$DebugForegroundColor = "Cyan",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$DebugBackgroundColor = "Black",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$VerboseForegroundColor = "Green",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$VerboseBackgroundColor = "Black",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$ProgressForegroundColor = "Yellow",

        [Parameter(ValueFromPipelineByPropertyName)]
        [ConsoleColor]$ProgressBackgroundColor = "DarkMagenta"
    )
    process {
        switch ($PSBoundParameters.Keys) {
            "Foreground" {
                $Host.UI.RawUI.ForegroundColor = $PSBoundParameters[$_]
            }
            "Background" {
                $Host.UI.RawUI.ForegroundColor = $PSBoundParameters[$_]
            }
            default {
                $Key = $_
                try {
                    $Host.PrivateData.$_ = $PSBoundParameters[$_]
                } catch {
                    Write-Debug "Adding $Key = '$($PSBoundParameters[$Key])' to Host.PrivateData"
                    Add-Member -InputObject $Host.PrivateData -NotePropertyName $Key -NotePropertyValue $PSBoundParameters[$Key] -ErrorAction SilentlyContinue
                }
            }
        }
    }
}
#EndRegion '.\Public\Set-PowerShellTheme.ps1' 73
#Region '.\postfix.ps1' 0
if (Get-Module EzTheme -ErrorAction SilentlyContinue) {
    Get-ModuleTheme | Set-PowerShellTheme
}
#EndRegion '.\postfix.ps1' 4