ESC key press in CMD prompt #7274

Closed
opened 2026-01-31 00:59:43 +00:00 by claunia · 15 comments
Owner

Originally created by @luke1961 on GitHub (Apr 4, 2020).

Originally assigned to: @DHowett-MSFT on GitHub.

Environment

Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd]
Windows Terminal version (if applicable):

Any other software?

Steps to reproduce

Expected behavior

Actual behavior

Originally created by @luke1961 on GitHub (Apr 4, 2020). Originally assigned to: @DHowett-MSFT on GitHub. <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: [run `[Environment]::OSVersion` for powershell, or `ver` for cmd] Windows Terminal version (if applicable): Any other software? ``` # Steps to reproduce <!-- A description of how to trigger this bug. --> # Expected behavior <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> # Actual behavior <!-- What's actually happening? -->
claunia added the Area-OutputIssue-BugResolution-ExternalProduct-Conpty labels 2026-01-31 00:59:44 +00:00
Author
Owner

@luke1961 commented on GitHub (Apr 4, 2020):

Environment:
Win32NT 10.0.18363.0 Microsoft Windows NT 10.0.18363.0
Conhost 10.0.18362.1

The problem is in pseudoconsole output when ESC key is pressed while running CMD.EXE.
Steps to reproduce:

  1. Programmatically set up Terminal to operate as a pseudoconsole, launch CMD.EXE
  2. Run and then exit (for example by pressing F10) Far Manager, version 2.0 (build 1807) x86. This step is critically important
  3. Type a number of characters in the command prompt
  4. Press ESC key
  5. You expect the characters to be erased and cursor come back to the beginning of line
    but the cursor does not come back even though the characters are erased.
    Here is my trace:

trace-1

Ignore the dashed lines, they separate the reads from pseudoconsole's output pipe. I typed 'j' 4 times and then pressed ESC. I see that after ESC is pressed the cursor is positioned at the right spot by ESC[26;5H but then spaces are sent to erase text. Unfortunately the spaces move the cursor.

Any ideas? Maybe something to do with console mode flags?

@luke1961 commented on GitHub (Apr 4, 2020): Environment: Win32NT 10.0.18363.0 Microsoft Windows NT 10.0.18363.0 Conhost 10.0.18362.1 The problem is in pseudoconsole output when ESC key is pressed while running CMD.EXE. Steps to reproduce: 1. Programmatically set up Terminal to operate as a pseudoconsole, launch CMD.EXE 2. Run and then exit (for example by pressing F10) Far Manager, version 2.0 (build 1807) x86. This step is critically important 3. Type a number of characters in the command prompt 4. Press ESC key 4. You expect the characters to be erased and cursor come back to the beginning of line but the cursor does not come back even though the characters are erased. Here is my trace: ![trace-1](https://user-images.githubusercontent.com/6032592/78460223-fff58180-768c-11ea-852b-792f69647c4a.jpg) Ignore the dashed lines, they separate the reads from pseudoconsole's output pipe. I typed 'j' 4 times and then pressed ESC. I see that after ESC is pressed the cursor is positioned at the right spot by ESC[26;5H but then spaces are sent to erase text. Unfortunately the spaces move the cursor. Any ideas? Maybe something to do with console mode flags?
Author
Owner

@luke1961 commented on GitHub (Apr 4, 2020):

Here is how the screen looks after ESC is pressed, chars erased but cursor in the wrong spot
screen

@luke1961 commented on GitHub (Apr 4, 2020): Here is how the screen looks after ESC is pressed, chars erased but cursor in the wrong spot ![screen](https://user-images.githubusercontent.com/6032592/78460354-1c45ee00-768e-11ea-9226-9c46f991683e.jpg)
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 6, 2020):

It's really interesting that this only happens after FAR manager's been launched.

@DHowett-MSFT commented on GitHub (Apr 6, 2020): It's really interesting that this only happens after FAR manager's been launched.
Author
Owner

@luke1961 commented on GitHub (Apr 6, 2020):

Also, I see that as soon as I type a char the cursor positioning escape sequence is sent. I have rebuilt OpenSSH (because it also uses pseudoconsole) with some trace code and the same behavior occurs. Almost looks like FAR Manager 'did something' to the pseusoconsole that makes it not flush all of its output.

@luke1961 commented on GitHub (Apr 6, 2020): Also, I see that as soon as I type a char the cursor positioning escape sequence is sent. I have rebuilt OpenSSH (because it also uses pseudoconsole) with some trace code and the same behavior occurs. Almost looks like FAR Manager 'did something' to the pseusoconsole that makes it not flush all of its output.
Author
Owner

@zadjii-msft commented on GitHub (Apr 6, 2020):

Unfortunately I'm not seeing this on the 10.0.19601.1000 DEP build I'm on. @DHowett-MSFT can you try and repro this on 19H2 compared with 20H1?

Maybe this has to do with our weird newBottomLine handling, that coincidentally might be getting much better as we speak

@zadjii-msft commented on GitHub (Apr 6, 2020): Unfortunately I'm not seeing this on the `10.0.19601.1000` DEP build I'm on. @DHowett-MSFT can you try and repro this on 19H2 compared with 20H1? Maybe this has to do with our weird `newBottomLine` handling, that coincidentally might be getting much better [as we speak](https://github.com/microsoft/terminal/pull/5181)
Author
Owner

@jdebp commented on GitHub (Apr 6, 2020):

It's interesting that 5 SPC characters are sent in order to blank out 4 j characters. Is your buffer differencing sensitive to where the cursor is? And shouldn't you be setting DECTCEM high after all of the update output? You seem, if I am understanding that trace correctly, to be setting it high before the final j character of those updates was output.

@jdebp commented on GitHub (Apr 6, 2020): It's interesting that 5 SPC characters are sent in order to blank out 4 `j` characters. Is your buffer differencing sensitive to where the cursor is? And shouldn't you be setting DECTCEM high *after* all of the update output? You seem, if I am understanding that trace correctly, to be setting it high *before* the final `j` character of those updates was output.
Author
Owner

@zadjii-msft commented on GitHub (Apr 6, 2020):

The whole trace looks like it's from a pretty old version of conpty tbh. There's a lot of optimizations we've done to emit less text, but I can't really recall what timeframe those were done in exactly.

There's clearly some bug that's happening here, but I'm 🤞 that this was actually already fixed ☺️

@zadjii-msft commented on GitHub (Apr 6, 2020): The whole trace looks like it's from a pretty old version of conpty tbh. There's a lot of optimizations we've done to emit less text, but I can't really recall what timeframe those were done in exactly. There's clearly some bug that's happening here, but I'm 🤞 that this was actually already fixed ☺️
Author
Owner

@luke1961 commented on GitHub (Apr 6, 2020):

I have installed Windows Terminal. Is there a way to force CreatePseudoConsole to use it instead of the old conhost which is on my system. maybe you can point me to a link about how to make it happen. It appears I have created a bug report for something which is in the rear view mirror for a while.

@luke1961 commented on GitHub (Apr 6, 2020): I have installed Windows Terminal. Is there a way to force CreatePseudoConsole to use it instead of the old conhost which is on my system. maybe you can point me to a link about how to make it happen. It appears I have created a bug report for something which is in the rear view mirror for a while.
Author
Owner

@zadjii-msft commented on GitHub (Apr 6, 2020):

I'm not sure there's really a recommended way at the moment unfortunately. This has been a pain area we've been thinking of solutions for actively, but don't have a definitive plan for quite yet. @DHowett-MSFT might have some ideas for workarounds for you

@zadjii-msft commented on GitHub (Apr 6, 2020): I'm not sure there's really a recommended way at the moment unfortunately. This has been a pain area we've been thinking of solutions for actively, but don't have a definitive plan for quite yet. @DHowett-MSFT might have some ideas for workarounds for you
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 8, 2020):

Does this specifically require far 2.0? I just (accidentally) tried it with Far 3.0.

Here's my results:

version status
rs3 (16299) there is no conpty
rs4 (17134) ✔️ cursor moves home
rs5 (17763) ✔️ cursor moves home
19h1 (18362) ✔️ cursor moves home
vb (19041) ✔️ cursor moves home
xx (unreleased) ✔️ cursor moves home

(also cool: this)

image

@DHowett-MSFT commented on GitHub (Apr 8, 2020): Does this specifically require _far 2.0_? I just (accidentally) tried it with Far 3.0. Here's my results: version|status -|- rs3 (16299)|:x: there is no conpty rs4 (17134)|✔️ cursor moves home rs5 (17763)|✔️ cursor moves home 19h1 (18362)|✔️ cursor moves home vb (19041)|✔️ cursor moves home xx (unreleased)|✔️ cursor moves home (also cool: this) ![image](https://user-images.githubusercontent.com/14316954/78733192-9a59fd00-78f9-11ea-9a4c-5cc63f2fa666.png)
Author
Owner

@luke1961 commented on GitHub (Apr 8, 2020):

Just tried with 'Far Manager, version 3.0.0.5555 x64' and the problem does NOT occur. It looks like it requires 'Far Manager, version 2.0 (build 1807) x86'. Do you have this version? I can easily zip my 'far 2.0' folder and attach it. Thank you for being persistent on this problem report. I am not married to 'far 2.0' in any way, just like it because it provides a good testing 'exercise' for my projects involving Windows Terminal.

@luke1961 commented on GitHub (Apr 8, 2020): Just tried with 'Far Manager, version 3.0.0.5555 x64' and the problem does NOT occur. It looks like it requires 'Far Manager, version 2.0 (build 1807) x86'. Do you have this version? I can easily zip my 'far 2.0' folder and attach it. Thank you for being persistent on this problem report. I am not married to 'far 2.0' in any way, just like it because it provides a good testing 'exercise' for my projects involving Windows Terminal.
Author
Owner

@luke1961 commented on GitHub (Apr 8, 2020):

Also, I was able to duplicate the problem using your VtPipeTerm tool. Options:

--debug --conpty --headless

I launched 'far 2.0', pressed F10 to terminate, got back into the command line, typed a couple of chars, pressed ESC and the cursor failed to return where it should.

conhost version: 6.3.18362.1
process tree:

image

@luke1961 commented on GitHub (Apr 8, 2020): Also, I was able to duplicate the problem using your VtPipeTerm tool. Options: --debug --conpty --headless I launched 'far 2.0', pressed F10 to terminate, got back into the command line, typed a couple of chars, pressed ESC and the cursor failed to return where it should. conhost version: 6.3.18362.1 process tree: ![image](https://user-images.githubusercontent.com/6032592/78738300-81644280-791f-11ea-8912-ae7cfc3ff49e.png)
Author
Owner

@zadjii-msft commented on GitHub (Apr 8, 2020):

I'm tempted to resolve this as external considering that this has always worked for Far 3.0, and only doesn't work in Far 2.0. I suppose we could try and take a look at what we're doing wrong in the Far 2.0 case, but I'm definitely inclined to endorse the workaround of "upgrade Far".

I'll let @DHowett-MSFT make the final call on this one

@zadjii-msft commented on GitHub (Apr 8, 2020): I'm tempted to resolve this as external considering that this has _always_ worked for Far 3.0, and only doesn't work in Far 2.0. I suppose we could try and take a look at what we're doing wrong in the Far 2.0 case, but I'm definitely inclined to endorse the workaround of "_upgrade Far_". I'll let @DHowett-MSFT make the final call on this one
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 8, 2020):

Okay, this is because FAR 2.0 turns off the display of the cursor. There's two issues here:

  1. When ConPTY believes the cursor is "hidden", it switches into a lazy updating mode. Since the user can't see it, it doesn't matter where it is.
  2. Until #2829 landed, ConPTY wouldn't tell the terminal that the cursor was hidden. This made the trickery we were doing in (1) very obvious and visible.

It's Far's job to restore the cursor state when it exits, and with #2829 merged ConPTY will now do the more correct thing (hide the cursor). 😄

Thanks!

@DHowett-MSFT commented on GitHub (Apr 8, 2020): Okay, this is because FAR 2.0 turns off the display of the cursor. There's two issues here: 1. When ConPTY believes the cursor is "hidden", it switches into a lazy updating mode. Since the user can't see it, it doesn't matter where it is. 2. Until #2829 landed, ConPTY _wouldn't tell the terminal_ that the cursor was hidden. This made the trickery we were doing in (1) very obvious and visible. It's Far's job to restore the cursor state when it exits, and with #2829 merged ConPTY will now do the more correct thing (hide the cursor). :smile: Thanks!
Author
Owner

@luke1961 commented on GitHub (Apr 9, 2020):

Thanks! Problem solved, I see the issue doesn't show in the latest build of the Terminal when I force VtPipeTerm to use the latest OpenConsole exceutable.

@luke1961 commented on GitHub (Apr 9, 2020): Thanks! Problem solved, I see the issue doesn't show in the latest build of the Terminal when I force VtPipeTerm to use the latest OpenConsole exceutable.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7274