From ef76ad9d1b8310a4681288d4ccf76c9da5fc6283 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 6 Jul 2022 15:35:09 -0700 Subject: [PATCH 1/2] Fix the ViModeIndicator = Cursor for Windows Terminal --- PSReadLine/ConsoleLib.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index ff8c1e6d9..42c43bf17 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -31,7 +31,7 @@ public int CursorTop set => Console.CursorTop = value; } - // .NET doesn't implement this API, so we fake it with a commonly supported escape sequence. + // .NET doesn't fully implement this API on all platforms, so we fake it with a commonly supported escape sequence. protected int _unixCursorSize = 25; public virtual int CursorSize { @@ -45,9 +45,15 @@ public virtual int CursorSize else { _unixCursorSize = value; - // Solid blinking block or blinking vertical bar - Write(value > 50 ? "\x1b[2 q" : "\x1b[5 q"); } + + // See the cursor ANSI codes at https://www.real-world-systems.com/docs/ANSIcode.html, searching for 'blinking block'. + // We write out the ANSI escape sequence even if we are on Windows, where the 'Console.CursorSize' API is supported by .NET. + // This is because this API works fine in console host, but not in Windows Terminal. The escape sequence will configure the + // cursor as expected in Windows Terminal, while in console host, the escape sequence works after it's written out, but then + // will be overwritten by 'CursorSize' when the user continues typing. + // We use blinking block and blinking underscore, so as to mimic the cursor size 100 and 25. + Write(value > 50 ? "\x1b[1 q" : "\x1b[3 q"); } } From af073aa288305d0fce7cf5aed86f26bb9401ebf3 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 6 Jul 2022 15:35:26 -0700 Subject: [PATCH 2/2] Update comment --- PSReadLine/ConsoleLib.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSReadLine/ConsoleLib.cs b/PSReadLine/ConsoleLib.cs index 42c43bf17..7cc53b341 100644 --- a/PSReadLine/ConsoleLib.cs +++ b/PSReadLine/ConsoleLib.cs @@ -52,7 +52,7 @@ public virtual int CursorSize // This is because this API works fine in console host, but not in Windows Terminal. The escape sequence will configure the // cursor as expected in Windows Terminal, while in console host, the escape sequence works after it's written out, but then // will be overwritten by 'CursorSize' when the user continues typing. - // We use blinking block and blinking underscore, so as to mimic the cursor size 100 and 25. + // We use blinking block and blinking underscore, so as to mimic the cursor size 100 and 25 in console host. Write(value > 50 ? "\x1b[1 q" : "\x1b[3 q"); } }