From 1577e51d258d27f50a9393fe191b1203effdeadb Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Tue, 30 Jun 2020 12:56:32 -0700 Subject: [PATCH 1/2] Do not force the background color during render Upcoming versions of the Windows Console will be able to differentiate a color set by the Win32 API from a color set by VT. This code transforms a Win32 color into a VT color, and then uses that VT color during rendering. When an enlightened console host receives this VT, it may handle it differently (translate it differently, reverse it differently, store it differently). Fixes #830. --- PSReadLine/Render.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 83ef4586..958454e5 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -122,8 +122,7 @@ private void Render() private void ForceRender() { - var defaultColor = VTColorUtils.MapColorToEscapeSequence(_console.ForegroundColor, isBackground: false) + - VTColorUtils.MapColorToEscapeSequence(_console.BackgroundColor, isBackground: true); + var defaultColor = VTColorUtils.MapColorToEscapeSequence(_console.ForegroundColor, isBackground: false); // Geneate a sequence of logical lines with escape sequences for coloring. int logicalLineCount = GenerateRender(defaultColor); From 9280b39bda0e0e7417ed7aff105fd3c20b68371a Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Tue, 30 Jun 2020 13:26:39 -0700 Subject: [PATCH 2/2] Instead, use 39;49 We'll also teach the various console implementations how to handle it. --- PSReadLine/PlatformWindows.cs | 2 ++ PSReadLine/Render.cs | 2 +- test/MockConsole.cs | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/PSReadLine/PlatformWindows.cs b/PSReadLine/PlatformWindows.cs index 7abc4bba..4fce03f6 100644 --- a/PSReadLine/PlatformWindows.cs +++ b/PSReadLine/PlatformWindows.cs @@ -416,6 +416,7 @@ internal class LegacyWin32Console : VirtualTerminal {45, () => Console.BackgroundColor = ConsoleColor.DarkMagenta}, {43, () => Console.BackgroundColor = ConsoleColor.DarkYellow}, {47, () => Console.BackgroundColor = ConsoleColor.Gray}, + {49, () => Console.BackgroundColor = InitialBG}, {100, () => Console.BackgroundColor = ConsoleColor.DarkGray}, {104, () => Console.BackgroundColor = ConsoleColor.Blue}, {102, () => Console.BackgroundColor = ConsoleColor.Green}, @@ -432,6 +433,7 @@ internal class LegacyWin32Console : VirtualTerminal {35, () => Console.ForegroundColor = ConsoleColor.DarkMagenta}, {33, () => Console.ForegroundColor = ConsoleColor.DarkYellow}, {37, () => Console.ForegroundColor = ConsoleColor.Gray}, + {39, () => Console.ForegroundColor = InitialFG}, {90, () => Console.ForegroundColor = ConsoleColor.DarkGray}, {94, () => Console.ForegroundColor = ConsoleColor.Blue}, {92, () => Console.ForegroundColor = ConsoleColor.Green}, diff --git a/PSReadLine/Render.cs b/PSReadLine/Render.cs index 958454e5..970e3f77 100644 --- a/PSReadLine/Render.cs +++ b/PSReadLine/Render.cs @@ -122,7 +122,7 @@ private void Render() private void ForceRender() { - var defaultColor = VTColorUtils.MapColorToEscapeSequence(_console.ForegroundColor, isBackground: false); + var defaultColor = "\x1b[39;49m"; // Geneate a sequence of logical lines with escape sequences for coloring. int logicalLineCount = GenerateRender(defaultColor); diff --git a/test/MockConsole.cs b/test/MockConsole.cs index 9d321c0d..a451d1a0 100644 --- a/test/MockConsole.cs +++ b/test/MockConsole.cs @@ -313,6 +313,7 @@ private static void ToggleNegative(TestConsole c, bool b) {"45", c => c.BackgroundColor = ConsoleColor.DarkMagenta}, {"43", c => c.BackgroundColor = ConsoleColor.DarkYellow}, {"47", c => c.BackgroundColor = ConsoleColor.Gray}, + {"49", c => c.BackgroundColor = DefaultBackground}, {"100", c => c.BackgroundColor = ConsoleColor.DarkGray}, {"104", c => c.BackgroundColor = ConsoleColor.Blue}, {"102", c => c.BackgroundColor = ConsoleColor.Green}, @@ -329,6 +330,7 @@ private static void ToggleNegative(TestConsole c, bool b) {"35", c => c.ForegroundColor = ConsoleColor.DarkMagenta}, {"33", c => c.ForegroundColor = ConsoleColor.DarkYellow}, {"37", c => c.ForegroundColor = ConsoleColor.Gray}, + {"39", c => c.ForegroundColor = DefaultForeground}, {"90", c => c.ForegroundColor = ConsoleColor.DarkGray}, {"94", c => c.ForegroundColor = ConsoleColor.Blue}, {"92", c => c.ForegroundColor = ConsoleColor.Green},