From e2846379b89cb8ca713dd27589cb13f11cfb7fe7 Mon Sep 17 00:00:00 2001 From: Alex Jordan Date: Thu, 28 Jul 2016 06:36:50 -0700 Subject: [PATCH] Fixing default and error colors for PSReadLine --- build.psm1 | 3 ++- .../host/msh/ConsoleHostRawUserInterface.cs | 23 ++----------------- .../host/msh/ConsoleHostUserInterface.cs | 12 ++++++---- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/build.psm1 b/build.psm1 index a87ccd54ac..1a493427e4 100644 --- a/build.psm1 +++ b/build.psm1 @@ -1489,9 +1489,10 @@ function script:Use-MSBuild { function script:log([string]$message) { Write-Host -Foreground Green $message + #reset colors for older package to at return to default after error message on a compiliation error + [console]::ResetColor() } - function script:precheck([string]$command, [string]$missedMessage) { $c = Get-Command $command -ErrorAction SilentlyContinue if (-not $c) { diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs index c6cf939509..ca1726418e 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostRawUserInterface.cs @@ -1520,16 +1520,11 @@ namespace Microsoft.PowerShell internal sealed class ConsoleHostRawUserInterface : PSHostRawUserInterface { - private ConsoleColor _defaultForeground = ConsoleColor.Gray; - - private ConsoleColor _defaultBackground = ConsoleColor.Black; private ConsoleHostUserInterface _parent = null; internal ConsoleHostRawUserInterface(ConsoleHostUserInterface mshConsole) : base() { - _defaultForeground = ForegroundColor; - _defaultBackground = BackgroundColor; _parent = mshConsole; } @@ -1539,14 +1534,7 @@ namespace Microsoft.PowerShell /// public override ConsoleColor BackgroundColor { - get - { - // Console can return UnknownColor, a private enum, equivalent - // to -1. When this is a case, map it instead to our default. - return Console.BackgroundColor == (ConsoleColor)(-1) - ? _defaultBackground - : Console.BackgroundColor; - } + get { return Console.BackgroundColor; } set { Console.BackgroundColor = value; } } @@ -1600,14 +1588,7 @@ namespace Microsoft.PowerShell /// public override ConsoleColor ForegroundColor { - get - { - // Console can return UnknownColor, a private enum, equivalent - // to -1. When this is a case, map it instead to our default. - return Console.ForegroundColor == (ConsoleColor)(-1) - ? _defaultForeground - : Console.ForegroundColor; - } + get { return Console.ForegroundColor; } set { Console.ForegroundColor = value; } } diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs index 1e1783fb21..e21dc0ac26 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs @@ -1450,7 +1450,8 @@ namespace Microsoft.PowerShell set { _errorForegroundColor = value; } } - private ConsoleColor _errorBackgroundColor = ConsoleColor.Black; + + private ConsoleColor _errorBackgroundColor = Console.BackgroundColor; public ConsoleColor ErrorBackgroundColor { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] @@ -1472,7 +1473,8 @@ namespace Microsoft.PowerShell set { _warningForegroundColor = value; } } - private ConsoleColor _warningBackgroundColor = ConsoleColor.Black; + + private ConsoleColor _warningBackgroundColor = Console.BackgroundColor; public ConsoleColor WarningBackgroundColor { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] @@ -1494,7 +1496,8 @@ namespace Microsoft.PowerShell set { _debugForegroundColor = value; } } - private ConsoleColor _debugBackgroundColor = ConsoleColor.Black; + + private ConsoleColor _debugBackgroundColor = Console.BackgroundColor; public ConsoleColor DebugBackgroundColor { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] @@ -1516,7 +1519,8 @@ namespace Microsoft.PowerShell set { _verboseForegroundColor = value; } } - private ConsoleColor _verboseBackgroundColor = ConsoleColor.Black; + + private ConsoleColor _verboseBackgroundColor = Console.BackgroundColor; public ConsoleColor VerboseBackgroundColor { [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]