Skip to content

Cursor shape gets reverted to legacy style after hiding the cursor and then making it visible again in console window #4124

Closed
@daxian-dbw

Description

@daxian-dbw

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):
linux

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-SettingsIssues related to settings and customizability, for console or terminalIssue-BugIt either shouldn't be doing this or needs an investigation.Needs-Tag-FixDoesn't match tag requirementsProduct-ConhostFor issues in the Console codebaseResolution-Fix-CommittedFix is checked in, but it might be 3-4 weeks until a release.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions