Closed
Description
Environment
Windows build number: Microsoft Windows [Version 10.0.18363.535]
Windows Terminal version (if applicable): NA
Any other software? No
Steps to reproduce
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
}
}
}
}
Expected behavior
Setting Console.CursorVisible
should not revert the cursor shape.
Actual behavior
The cursor shape gets reverted from Solid Box
to the legacy style (Underline
):
Related issues
#409 and #1145 and PowerShell/PSReadLine#903
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.