Skip to content

Commit fbaba3e

Browse files
authored
Fix ViModeIndicator = Cursor for Windows Terminal (#3374)
1 parent 36893ee commit fbaba3e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

PSReadLine/ConsoleLib.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public int CursorTop
3131
set => Console.CursorTop = value;
3232
}
3333

34-
// .NET doesn't implement this API, so we fake it with a commonly supported escape sequence.
34+
// .NET doesn't fully implement this API on all platforms, so we fake it with a commonly supported escape sequence.
3535
protected int _unixCursorSize = 25;
3636
public virtual int CursorSize
3737
{
@@ -45,9 +45,15 @@ public virtual int CursorSize
4545
else
4646
{
4747
_unixCursorSize = value;
48-
// Solid blinking block or blinking vertical bar
49-
Write(value > 50 ? "\x1b[2 q" : "\x1b[5 q");
5048
}
49+
50+
// See the cursor ANSI codes at https://www.real-world-systems.com/docs/ANSIcode.html, searching for 'blinking block'.
51+
// We write out the ANSI escape sequence even if we are on Windows, where the 'Console.CursorSize' API is supported by .NET.
52+
// This is because this API works fine in console host, but not in Windows Terminal. The escape sequence will configure the
53+
// cursor as expected in Windows Terminal, while in console host, the escape sequence works after it's written out, but then
54+
// will be overwritten by 'CursorSize' when the user continues typing.
55+
// We use blinking block and blinking underscore, so as to mimic the cursor size 100 and 25 in console host.
56+
Write(value > 50 ? "\x1b[1 q" : "\x1b[3 q");
5157
}
5258
}
5359

0 commit comments

Comments
 (0)