Windows build number: Microsoft Windows [Version 10.0.18363.535]
Windows Terminal version (if applicable): NA
Any other software? No
After setting the cursor shape in Properties->Terminal
, hiding and then showing the cursor by setting Console.CursorVisible
to false
and then true
causes the cursor shape to be restored to the legacy style in console host.
The following simple C# program can show the problem:
using System;
using System.Text;
namespace cursorShape
{
class Program
{
static void Main(string[] args)
{
const string prompt = "PROMP> ";
StringBuilder sb = new StringBuilder();
int top = Console.CursorTop;
Console.OutputEncoding = Encoding.UTF8;
Console.Write(prompt);
while (true)
{
var key = Console.ReadKey();
if (key.Key == ConsoleKey.Q)
{
break;
}
sb.Append(key.KeyChar);
Console.CursorVisible = false; // Hide the cursor before rewriting
Console.SetCursorPosition(0, top);
Console.Write($"{prompt}{sb}");
Console.SetCursorPosition(Console.CursorLeft, top);
Console.CursorVisible = true; // Show the cursor afterwards
}
}
}
}
Setting Console.CursorVisible
should not revert the cursor shape.
The cursor shape gets reverted from Solid Box
to the legacy style (Underline
):
Those 2 issues were reported in the PowerShell+PSReadLine context. PSReadLine depends on Console.CursorVisible
to hide and show the cursor during rendering, so the cursor shape gets reverted.
Well, heck.
As explained in #409, the problem is that calling the SetConsoleCursorInfo
sets the cursor size, and setting the cursor size forces the cursor shape back to the legacy style (because that's the only shape for which the size is applicable AFAIK).
It's easy enough to "fix". We could just delete this line from the SetCursorInformation
method:
https://github.com/microsoft/terminal/blob/6f667f48ae109d4291cda1f8d4e977315c0dae8a/src/host/screenInfo.cpp#L1778
But that's a change in behavior for a public API, and it's possible some applications could actually be relying on that behavior (although I would think that unlikely).
Ideally the Console.CursorVisible
property should be using an API that just sets the visibility and nothing else, but but I don't think there is such a thing. The best you could do is use a VT sequence, but that's obviously not going to work with older versions of Windows.
:tada:This issue was addressed in #5251, which has now been successfully released as Windows Terminal Preview v0.11.1121.0
.:tada:
Handy links:
Most helpful comment
:tada:This issue was addressed in #5251, which has now been successfully released as
Windows Terminal Preview v0.11.1121.0
.:tada:Handy links: