From edda43dfb48d77087487c27f991be84f5c8a0da8 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Wed, 30 Oct 2019 12:24:25 -0700 Subject: [PATCH] Fix use of accent colors for hosts that don't support them (#10937) --- .../PowerShellCore_format_ps1xml.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index e8c2f2e7b..a4b3127a4 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -759,7 +759,12 @@ namespace System.Management.Automation.Runspaces $newline = [Environment]::Newline $output = [System.Text.StringBuilder]::new() $prefix = ' ' * $indent - $accentColor = Get-VT100Color $Host.PrivateData.FormatAccentColor + $accentColor = '' + + if ($null -ne $Host.PrivateData) { + $accentColor = Get-VT100Color ($Host.PrivateData.FormatAccentColor ?? $Host.PrivateData.ErrorForegroundColor) + } + $expandTypes = @( 'Microsoft.Rest.HttpRequestMessageWrapper' 'Microsoft.Rest.HttpResponseMessageWrapper' @@ -1004,9 +1009,10 @@ namespace System.Management.Automation.Runspaces $errorColor = '' $accentColor = '' - if ($Host.PrivateData) { - $errorColor = Get-VT100Color -color $Host.PrivateData.ErrorForegroundColor - $accentColor = Get-VT100Color -color $Host.PrivateData.ErrorAccentColor + + if ($null -ne $Host.PrivateData) { + $errorColor = Get-VT100Color $Host.PrivateData.ErrorForegroundColor + $accentColor = Get-VT100Color ($Host.PrivateData.ErrorAccentColor ?? $errorColor) } $posmsg = ''