From 66ee25c603762f744d5ab189dabf2fe63cd7da99 Mon Sep 17 00:00:00 2001 From: George Fleming Date: Thu, 28 Apr 2016 11:43:14 -0700 Subject: [PATCH] Change default colors, and show highlighted text properly --- src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs | 16 +++++++++++++++- src/Microsoft.PowerShell.PSReadLine/Render.cs | 6 ++++++ .../ScreenCapture.cs | 8 ++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs index 1d5ae638e8..56fece1653 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs @@ -72,6 +72,20 @@ namespace Microsoft.PowerShell public class PSConsoleReadlineOptions { +#if CORECLR + public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.Magenta; + public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; + public const ConsoleColor DefaultOperatorForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultVariableForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultCommandForegroundColor = ConsoleColor.Yellow; + public const ConsoleColor DefaultParameterForegroundColor = ConsoleColor.Green; + public const ConsoleColor DefaultTypeForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultNumberForegroundColor = ConsoleColor.White; + public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; + public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; + public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; +#else public const ConsoleColor DefaultCommentForegroundColor = ConsoleColor.DarkGreen; public const ConsoleColor DefaultKeywordForegroundColor = ConsoleColor.Green; public const ConsoleColor DefaultStringForegroundColor = ConsoleColor.DarkCyan; @@ -84,7 +98,7 @@ namespace Microsoft.PowerShell public const ConsoleColor DefaultMemberForegroundColor = ConsoleColor.Gray; public const ConsoleColor DefaultEmphasisForegroundColor = ConsoleColor.Cyan; public const ConsoleColor DefaultErrorForegroundColor = ConsoleColor.Red; - +#endif public const EditMode DefaultEditMode = EditMode.Windows; diff --git a/src/Microsoft.PowerShell.PSReadLine/Render.cs b/src/Microsoft.PowerShell.PSReadLine/Render.cs index 73be581284..fb7cec8076 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Render.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Render.cs @@ -472,8 +472,14 @@ namespace Microsoft.PowerShell // to invert only the lower 3 bits to change the color is somewhat // but looks best with the 2 default color schemes - starting PowerShell // from it's shortcut or from a cmd shortcut. +#if CORECLR + ConsoleColor tempColor = ((int)foregroundColor == -1) ? ConsoleColor.White : foregroundColor; + foregroundColor = ((int)backgroundColor == -1) ? ConsoleColor.Black : backgroundColor; + backgroundColor = tempColor; +#else foregroundColor = (ConsoleColor)((int)foregroundColor ^ 7); backgroundColor = (ConsoleColor)((int)backgroundColor ^ 7); +#endif } charInfo.ForegroundColor = foregroundColor; diff --git a/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs b/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs index be053566a4..2659fec974 100644 --- a/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs +++ b/src/Microsoft.PowerShell.PSReadLine/ScreenCapture.cs @@ -19,8 +19,16 @@ namespace Microsoft.PowerShell var buffer = ReadBufferLines(start, count); for (int i = 0; i < buffer.Length; i++) { +#if CORECLR + ConsoleColor tempColor = (int)buffer[i].ForegroundColor == -1 + ? ConsoleColor.White : buffer[i].ForegroundColor; + buffer[i].ForegroundColor = (int)buffer[i].BackgroundColor == -1 + ? ConsoleColor.Black : buffer[i].BackgroundColor; + buffer[i].BackgroundColor = tempColor; +#else buffer[i].ForegroundColor = (ConsoleColor)((int)buffer[i].ForegroundColor ^ 7); buffer[i].BackgroundColor = (ConsoleColor)((int)buffer[i].BackgroundColor ^ 7); +#endif } _singleton._console.WriteBufferLines(buffer, ref start, false); }