Theme.PSStyle.psm1
using namespace PoshCode.Pansies using namespace System.Management.Automation #Region '.\Public\Get-PSStyleTheme.ps1' 0 #using namespace PoshCode.Pansies #using namespace System.Management.Automation function Get-PSStyleTheme { <# .SYNOPSIS Returns a hashtable of the _current_ values that can be splatted to Set-Theme #> [CmdletBinding()] param( # If specified, returns the named color scheme instead of the one associated with the current profile [Parameter(ValueFromPipeline)] [string]$ColorScheme ) process { if ($null -ne 'System.Management.Automation.PSStyle' -as [type]) { $ErrorMessage = 'PSStyle is not supported by this version of PowerShell.' $Exception = [PSInvalidOperationException]::new($ErrorMessage) $PSCmdlet.ThrowTerminatingError([ErrorRecord]::new($Exception, "PSStyle Unsupported", "InvalidData", $Host.PrivateData)) } $Result = [Ordered]@{ PSTypeName = "Theme.PSStyle" } $Simple, $Container = ($PSStyle | Get-Member -MemberType Property).Where({ $_.Definition -Match "^string|^int|^bool|OutputRendering" }, "Split") foreach($Property in $Simple) { $Result[$Property.Name] = $PSStyle.$($Property.Name) } foreach($Nested in $Container) { $Simple, $NestedFurther = ($PSStyle.$($Nested.Name) | Get-Member -MemberType Property).Where({ $_.Definition -Match "^string|^int|^bool|ProgressView" }, "Split") # $Result[$Nested.Name] = @{} foreach ($Property in $Simple) { #$Result[$Nested.Name][$Property.Name] = $PSStyle.$($Nested.Name).$($Property.Name) $Result[$Nested.Name + '_' + $Property.Name] = $PSStyle.$($Nested.Name).$($Property.Name) } foreach ($Furthest in $NestedFurther) { $Simple, $NestedFurthest = ($PSStyle.$($Nested.Name).$($Furthest.Name) | Get-Member -MemberType Property).Where({ $_.Definition -Match "^string|^int|^bool" }, "Split") # $Result[$Nested.Name][$Furthest.Name] = @{} foreach ($Property in $Simple) { # $Result[$Nested.Name][$Furthest.Name][$Property.Name] = $PSStyle.$($Nested.Name).$($Furthest.Name).$($Property.Name) $Result[$Nested.Name + '_' + $Furthest.Name + '_' + $Property.Name] = $PSStyle.$($Nested.Name).$($Furthest.Name).$($Property.Name) } if ("PSStyle.$($Nested.Name).$($Furthest.Name).$($NestedFurthest.Name)" -ne "PSStyle.FileInfo.Extension.Keys") { Write-Warning "Unsupported PSStyle: PSStyle.$($Nested.Name).$($Furthest.Name).$($NestedFurthest.Name)`nPlease file an issue to let me know https://github.com/Jaykul/EzTheme/issues" } } } # Special case for the FileInfo $Result["FileInfo_Extension"] = @{} foreach ($ext in $PSStyle.FileInfo.Extension.Keys) { #$Result.FileInfo.Extension[$ext] = $PSStyle.FileInfo.Extension[$ext] $Result["FileInfo_Extension"][$ext] = $PSStyle.FileInfo.Extension[$ext] } [PSCustomObject]$Result } } #EndRegion '.\Public\Get-PSStyleTheme.ps1' 62 #Region '.\Public\Set-PSStyleTheme.ps1' 0 #using namespace PoshCode.Pansies function Set-PSStyleTheme { <# .SYNOPSIS Set the PSStyle for PowerShell output Has parameters for all the current PSStyle options #> [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName)] $OutputRendering, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Formatting.Debug")] $Formatting_Debug, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Formatting.Error")] $Formatting_Error, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Formatting.ErrorAccent")] $Formatting_ErrorAccent, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Formatting.FormatAccent")] $Formatting_FormatAccent, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Formatting.TableHeader")] $Formatting_TableHeader, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Formatting.Verbose")] $Formatting_Verbose, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Formatting.Warning")] $Formatting_Warning, [Parameter(ValueFromPipelineByPropertyName)] [Alias("FileInfo.Directory")] $FileInfo_Directory, [Parameter(ValueFromPipelineByPropertyName)] [Alias("FileInfo.Executable")] $FileInfo_Executable, [Parameter(ValueFromPipelineByPropertyName)] [Alias("FileInfo.Extension")] $FileInfo_Extension, [Parameter(ValueFromPipelineByPropertyName)] [Alias("FileInfo.SymbolicLink")] $FileInfo_SymbolicLink, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Progress.MaxWidth")] $Progress_MaxWidth, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Progress.Style")] $Progress_Style, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Progress.UseOSCIndicator")] $Progress_UseOSCIndicator, [Parameter(ValueFromPipelineByPropertyName)] [Alias("Progress.View")] $Progress_View ) process { if (!('System.Management.Automation.PSStyle' -as [type])) { Write-Warning '$PSStyle is not used by this version of PowerShell. These theme settings may not work as intended.' } if ($PSBoundParameters.ContainsKey("OutputRendering")) { $PSStyle.OutputRendering = $OutputRendering } if ($PSBoundParameters.ContainsKey("Formatting_FormatAccent")) { $PSStyle.Formatting.FormatAccent = $Formatting_FormatAccent } if ($PSBoundParameters.ContainsKey("Formatting_TableHeader")) { $PSStyle.Formatting.TableHeader = $Formatting_TableHeader } if ($PSBoundParameters.ContainsKey("Formatting_ErrorAccent")) { $PSStyle.Formatting.ErrorAccent = $Formatting_ErrorAccent } if ($PSBoundParameters.ContainsKey("Formatting_Error")) { $PSStyle.Formatting.Error = $Formatting_Error } if ($PSBoundParameters.ContainsKey("Formatting_Warning")) { $PSStyle.Formatting.Warning = $Formatting_Warning } if ($PSBoundParameters.ContainsKey("Formatting_Verbose")) { $PSStyle.Formatting.Verbose = $Formatting_Verbose } if ($PSBoundParameters.ContainsKey("Formatting_Debug")) { $PSStyle.Formatting.Debug = $Formatting_Debug } if ($PSBoundParameters.ContainsKey("Progress_Style")) { $PSStyle.Progress.Style = $Progress_Style } if ($PSBoundParameters.ContainsKey("Progress_MaxWidth")) { $PSStyle.Progress.MaxWidth = $Progress_MaxWidth } if ($PSBoundParameters.ContainsKey("Progress_View")) { $PSStyle.Progress.View = $Progress_View } if ($PSBoundParameters.ContainsKey("Progress_UseOSCIndicator")) { $PSStyle.Progress.UseOSCIndicator = $Progress_UseOSCIndicator } if ($PSBoundParameters.ContainsKey("FileInfo_Directory")) { $PSStyle.FileInfo.Directory = $FileInfo_Directory } if ($PSBoundParameters.ContainsKey("FileInfo_SymbolicLink")) { $PSStyle.FileInfo.SymbolicLink = $FileInfo_SymbolicLink } if ($PSBoundParameters.ContainsKey("FileInfo_Executable")) { $PSStyle.FileInfo.Executable = $FileInfo_Executable } if ($PSBoundParameters.ContainsKey("FileInfo_Extension")) { foreach($key in $FileInfo_Extension.Keys) { $PSStyle.FileInfo.Extension[$key] = $FileInfo_Extension[$key] } } } } #EndRegion '.\Public\Set-PSStyleTheme.ps1' 122 #Region '.\postfix.ps1' 0 if (Get-Module EzTheme -ErrorAction SilentlyContinue) { Get-ModuleTheme | Set-PSStyleTheme } #EndRegion '.\postfix.ps1' 4 |