Skip to content

Commit e4c97df

Browse files
DHowettdaxian-dbw
authored andcommitted
Teach PSReadline to not force the background color during render (#1626)
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). Use `39;49` for the default foreground/background. We'll also teach the various console implementations how to handle it.
1 parent f8b004a commit e4c97df

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

PSReadLine/PlatformWindows.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ internal class LegacyWin32Console : VirtualTerminal
416416
{45, () => Console.BackgroundColor = ConsoleColor.DarkMagenta},
417417
{43, () => Console.BackgroundColor = ConsoleColor.DarkYellow},
418418
{47, () => Console.BackgroundColor = ConsoleColor.Gray},
419+
{49, () => Console.BackgroundColor = InitialBG},
419420
{100, () => Console.BackgroundColor = ConsoleColor.DarkGray},
420421
{104, () => Console.BackgroundColor = ConsoleColor.Blue},
421422
{102, () => Console.BackgroundColor = ConsoleColor.Green},
@@ -432,6 +433,7 @@ internal class LegacyWin32Console : VirtualTerminal
432433
{35, () => Console.ForegroundColor = ConsoleColor.DarkMagenta},
433434
{33, () => Console.ForegroundColor = ConsoleColor.DarkYellow},
434435
{37, () => Console.ForegroundColor = ConsoleColor.Gray},
436+
{39, () => Console.ForegroundColor = InitialFG},
435437
{90, () => Console.ForegroundColor = ConsoleColor.DarkGray},
436438
{94, () => Console.ForegroundColor = ConsoleColor.Blue},
437439
{92, () => Console.ForegroundColor = ConsoleColor.Green},

PSReadLine/Render.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ private void Render()
122122

123123
private void ForceRender()
124124
{
125-
var defaultColor = VTColorUtils.MapColorToEscapeSequence(_console.ForegroundColor, isBackground: false) +
126-
VTColorUtils.MapColorToEscapeSequence(_console.BackgroundColor, isBackground: true);
125+
var defaultColor = "\x1b[39;49m";
127126

128127
// Geneate a sequence of logical lines with escape sequences for coloring.
129128
int logicalLineCount = GenerateRender(defaultColor);

test/MockConsole.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ private static void ToggleNegative(TestConsole c, bool b)
313313
{"45", c => c.BackgroundColor = ConsoleColor.DarkMagenta},
314314
{"43", c => c.BackgroundColor = ConsoleColor.DarkYellow},
315315
{"47", c => c.BackgroundColor = ConsoleColor.Gray},
316+
{"49", c => c.BackgroundColor = DefaultBackground},
316317
{"100", c => c.BackgroundColor = ConsoleColor.DarkGray},
317318
{"104", c => c.BackgroundColor = ConsoleColor.Blue},
318319
{"102", c => c.BackgroundColor = ConsoleColor.Green},
@@ -329,6 +330,7 @@ private static void ToggleNegative(TestConsole c, bool b)
329330
{"35", c => c.ForegroundColor = ConsoleColor.DarkMagenta},
330331
{"33", c => c.ForegroundColor = ConsoleColor.DarkYellow},
331332
{"37", c => c.ForegroundColor = ConsoleColor.Gray},
333+
{"39", c => c.ForegroundColor = DefaultForeground},
332334
{"90", c => c.ForegroundColor = ConsoleColor.DarkGray},
333335
{"94", c => c.ForegroundColor = ConsoleColor.Blue},
334336
{"92", c => c.ForegroundColor = ConsoleColor.Green},

0 commit comments

Comments
 (0)