-
Notifications
You must be signed in to change notification settings - Fork 312
Garbage characters get inserted into the input line while pressing left right arrow keys #658
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
Comments
@jianyunt - without that loop, events will not be processed until after accepting input (the user pressed Enter) - this could delay event processing for hours or more, e.g. when the user is away from the computer. I'm not 100% certain here, but I suspect the event processing is taking too long, and when that happens, the tty decides to print the output because it wasn't consumed. I'd take a look at |
I think @lzybkr's theory is correct. This can easily repro by replacing the |
As I described, the event processing within In my ideal world, the console host wouldn't need to call I don't remember the difficulties I hit, but I likely did not have enough time to work through them, I don't recall any fundamental reason why that approach couldn't work. That said, it might make sense for cloudshell to create a background runspace and process events in that runspace instead of the default runspace. |
According to @Tyriar, appending |
It's possible |
Here's what I observed when @jianyunt visited on Friday, the terminal emulator is sending the correct sequences to PowerShell and since PS rewrites the prompt whenever input is changed or cursor movement happens, it's a problem with how PS is handling the incoming text stream. Other shells like bash and zsh handle this fine. I don't know enough about PS to know if it's a problem with the core or readline though. A very easy to repro scenario that's similar to this is to launch a terminal with bash, then run pwsh and hit left arrow several times as it's launching. |
@lzybkr this may be related to the issue I mentioned in #626. The So there is already a pending |
@Tyriar - PSReadLine 2.0.0-beta1 does not rewrite like it did in 1.2. It only touches the prompt if there is a syntax error or if asked to call the prompt function, e.g. after showing possible completions. The startup scenario can impact @SeeminglyScience - thanks for chiming in. Maybe it's worth an experiment to remove the code querying the cursor position. If that fixes the problem, I'm still not sure what the best option is, but one option would be to live with the somewhat poor experience if an event handler writes to stdout (which is arguably an unfriendly event handler anyway). |
The root cause seems to be https://github.com/dotnet/corefx/issues/29669. |
By pressing and holding the left or right arrow keys you will see ascii sequence key code (OC, OD) gets inserted into your input string. The issue is reproducible on a Linux native terminal too. But on cloudshell it is easy to repro. The output looks like:
Initial Investigation
I am using the 2.0 PSReadline module. To repro it on Linux, I just run Register-EventObject to create a background job - that's what the cloudshell does for Azure token handling. It seems as long as a user has background jobs running, he will likely encounter the issue while pressing and holding Left and Right arrow keys or doing inputs on Linux machine.
It looks like the PSReadline is handling eventSubscribers. In this case, it found 3 subscribers so entered the code block from line 184 to 231. I am not sure what this code block is trying to archive, but if I comment them out, the issue disappears and all key press seems start working properly.
Environment data
Steps to reproduce or exception report
Ubuntu 16.04.1 LTS (Xenial Xerus) . Note I did not try on other distro
or http//portal.azure.com and click on CloudShell
pwsh
run the above script to register some events if you are trying on your own Linux machine
type Hello and press and hold left or right arrow key
The text was updated successfully, but these errors were encountered: