Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cursor shape not preserved #903

Closed
breyed opened this issue Apr 24, 2019 · 9 comments
Closed

Cursor shape not preserved #903

breyed opened this issue Apr 24, 2019 · 9 comments
Assignees

Comments

@breyed
Copy link

breyed commented Apr 24, 2019

PSReadLine resets the cursor shape, causing the user's setting to no longer be applied. If PSReadLine has a reason to change the cursor shape temporarily, it should restore the user's setting when it's done.
Migrated from microsoft/terminal#409.
Duplicate: microsoft/terminal#1145 -- it has detailed repro steps to show the problem.

Note

This is not related to the VI edit mode.
This only happens when setting cursor shape in the Terminal tab in console host.
When using Windows Terminal and set the cursor shape in Profile.json, the cursor doesn't get reset by PSReadLine.

Environment data

PS version: 7.0.0-rc.1
PSReadline version: 2.0.0-rc1
os: 10.0.18362.1 (WinBuild.160101.0800)
PS file version: 7.0.0.0
HostName: ConsoleHost
BufferWidth: 145
BufferHeight: 9001

Steps to reproduce or exception report

  1. Open pwsh in console host
  2. Right click on a console window and select Properties -> Terminal
  3. Set the Cursor Shape to anything other than "Use Legacy Style"
  4. Notice that the cursor shows up correctly but after hitting enter and typing a few characters, it returns to the default style
  5. Repeat step 1 and notice that your setting has been reverted to "Use Legacy Style"
@reynoldsbd
Copy link

Noticed the same behavior. In my case, the cursor changes back to legacy shape as soon as I start typing.

@Johbii
Copy link

Johbii commented Jul 13, 2019

Same thing happens to me. Typing immediately changes the cursor back to default shape. Removing the module using "Remove-Module PSReadline" fixes the issue.

@Johbii
Copy link

Johbii commented Jul 17, 2019

This has been bugging me for a long time, I hope this is fixed soon.

@lzybkr
Copy link
Member

lzybkr commented Jul 18, 2019

I only see code that changes the cursor size in Vi mode with the ViModeIndicator=Cursor. Neither setting is a default.

Are folks seeing this problem with other modes?

Assuming so (based on the number of comments/thumbs up), I wonder if the cursor size is being changed in .Net somehow?

@gwojan
Copy link

gwojan commented Jul 18, 2019

@lzybkr This only became an issue for me once I upgraded to Windows 10 1903.

I've seen this behavior in the default Windows mode and Vi mode.

@Johbii
Copy link

Johbii commented Jul 20, 2019

I have this in the default editing mode as well, I tried to enable Vi mode to test but I was not sure if it worked.

@DHowett-MSFT
Copy link

Related to #964

@daxian-dbw daxian-dbw added the Needs-More Investigation Initial investigation is done, but need to follow up. label Jan 3, 2020
@daxian-dbw
Copy link
Member

I think this is probably related to PSReadLine resetting the OutputEncoding after every operation. Will look closer and report back.

@daxian-dbw daxian-dbw self-assigned this Jan 3, 2020
@daxian-dbw
Copy link
Member

daxian-dbw commented Jan 6, 2020

OK, it turns out setting Console.CursorVisible to false and then back to true causes the cursor shape to be restored to the legacy style in console host.
I can reproduce it with a simple C# echo program:

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
            }
        }
    }
}

linux


Logged the issue microsoft/terminal#4124 in Windows Terminal repo.
I will close this issue as an external issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants