Backspacing a tab character in conpty causes visual corruption #5579

Closed
opened 2026-01-31 00:16:32 +00:00 by claunia · 10 comments
Owner

Originally created by @getkirill on GitHub (Dec 15, 2019).

Environment

Windows build number: 18362.476
Windows Terminal version (if applicable): 0.7.3451.0

Python 3.5>>> 3.8

Steps to reproduce

Add to config file:

{
            // Make changes here to the python.exe profile
            "guid": "{0cab0dad-35be-5f56-a8ff-afceeeaa6101}",
            "name": "Python",
            "commandline": "C:\\Program Files\\Python35\\python.exe",
            "hidden": false,
	    "backgroundImage": "C:\\Users\\noncyrilicusername\\Documents\\DDLC\\extract\\src\\images.rpa\\images\\cg\\credits\\1.png",
            "backgroundImageOpacity": 0.5,
	    "icon": "C:\\Program Files\\Python35\\icon.png"
        }

Launch new tab, try to write text, press Enter, press Up Arrow, try to edit

Expected behavior

Normal text

Actual behavior

image

Originally created by @getkirill on GitHub (Dec 15, 2019). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 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: 18362.476 Windows Terminal version (if applicable): 0.7.3451.0 Python 3.5>>> 3.8 ``` # Steps to reproduce Add to config file: ```none { // Make changes here to the python.exe profile "guid": "{0cab0dad-35be-5f56-a8ff-afceeeaa6101}", "name": "Python", "commandline": "C:\\Program Files\\Python35\\python.exe", "hidden": false, "backgroundImage": "C:\\Users\\noncyrilicusername\\Documents\\DDLC\\extract\\src\\images.rpa\\images\\cg\\credits\\1.png", "backgroundImageOpacity": 0.5, "icon": "C:\\Program Files\\Python35\\icon.png" } ``` <!-- A description of how to trigger this bug. --> Launch new tab, try to write text, press Enter, press Up Arrow, try to edit # Expected behavior Normal text <!-- A description of what you're expecting, possibly containing screenshots or reference material. --> # Actual behavior ![image](https://user-images.githubusercontent.com/26975352/70862493-32e4ff80-1f4e-11ea-85c3-bfc7a41818e2.png) <!-- What's actually happening? -->
Author
Owner

@zadjii-msft commented on GitHub (Dec 16, 2019):

@getkirill I'm not seeing this repro with python 3.7.5 - could you try updating python to see if that fixes it?
image

If it doesn't, then I think I'm going to need some more specific steps to help repro this. Exactly what input is causing this to repro? Does it repro in a plain old conhost/Console window?

@zadjii-msft commented on GitHub (Dec 16, 2019): @getkirill I'm not seeing this repro with python 3.7.5 - could you try updating python to see if that fixes it? ![image](https://user-images.githubusercontent.com/18356694/70911623-e0502580-1fd7-11ea-8cad-899745284f25.png) If it doesn't, then I think I'm going to need some more specific steps to help repro this. Exactly what input is causing this to repro? Does it repro in a plain old conhost/Console window?
Author
Owner

@getkirill commented on GitHub (Dec 18, 2019):

@zadjii-msft I use config with python cmd, + i upgraded python to 3.8.

@getkirill commented on GitHub (Dec 18, 2019): @zadjii-msft I use config with python cmd, + i upgraded python to 3.8.
Author
Owner

@zadjii-msft commented on GitHub (Dec 18, 2019):

Okay so it's not dependent upon python version. Could I get some literal text that repros this bug for you? I can't get it to happen on my end by just entering commands and attempting to use the up arrow to navigate the history.

@zadjii-msft commented on GitHub (Dec 18, 2019): Okay so it's not dependent upon python version. Could I get some literal text that repros this bug for you? I can't get it to happen on my end by just entering commands and attempting to use the up arrow to navigate the history.
Author
Owner

@strayge commented on GitHub (Dec 18, 2019):

windows 10.0.19037.1
terminal 0.7.3451.0
python 3.7.4

Steps to reproduce:

  1. open new "cmd" tab
  2. run "python"
  3. write text with tab identation, ex.: <tab>123
    in terminal it now looks like:
    >>>     123
  4. move cursor to <tab> character and delete it with <Backspace>/<Del>
  5. terminal shows
    >>> 123 123
@strayge commented on GitHub (Dec 18, 2019): windows 10.0.19037.1 terminal 0.7.3451.0 python 3.7.4 Steps to reproduce: 1) open new "cmd" tab 2) run "python" 3) write text with tab identation, ex.: `<tab>123` in terminal it now looks like: <pre>>>> 123</pre> 4) move cursor to `<tab>` character and delete it with `<Backspace>`/`<Del>` 5) terminal shows <pre>>>> 123 123</pre>
Author
Owner

@zadjii-msft commented on GitHub (Dec 18, 2019):

Okay, that's much more helpful. Thanks!

@zadjii-msft commented on GitHub (Dec 18, 2019): Okay, that's much more helpful. Thanks!
Author
Owner

@j4james commented on GitHub (Dec 24, 2019):

Note that this is a conhost bug, and as far as I can tell, it only occurs when VT mode is enabled (i.e. you've set the VirtualTerminalLevel registry entry).

The issue is that the WriteCharsLegacy method handles tabs differently in VT mode, and doesn't update the number of spaces written. If you look at the section of code where the tab is processed, you'll see that TempNumSpaces is only updated in the non-VT branch. As a result, the _visibleCharCount in the COOKED_READ_DATA class is not updated correctly, and the DeleteCommandLine method then doesn't fully clear the line when backspacing.

It's possible this could be fixed just by updating TempNumSpaces with the distance that the cursor is moved in VT mode, but I don't know what other implications that would have. Also, the fact that we've got legacy code receiving VT-specific behavior is probably going to cause all sorts of other problems, because the two tab types are really quite different. That's potentially a bigger issue.

Long term, I think it would be preferable if we could get rid of all of this VT-specific code in the WriteCharsLegacy method and just let the AdaptDispatch class have its own text writer that follows the VT rules (I'm hoping that's what #780 is going to achieve). Short term maybe we should be passing a flag to WriteCharsLegacy to say whether any VT behavior is allowed. In fact, the existing WC_DELAY_EOL_WRAP flag could possibly be repurposed for that.

@j4james commented on GitHub (Dec 24, 2019): Note that this is a conhost bug, and as far as I can tell, it only occurs when VT mode is enabled (i.e. you've set the _VirtualTerminalLevel_ registry entry). The issue is that the `WriteCharsLegacy` method handles tabs differently in VT mode, and doesn't update the number of spaces written. If you look at [the section of code where the tab is processed](https://github.com/microsoft/terminal/blob/6f667f48ae109d4291cda1f8d4e977315c0dae8a/src/host/_stream.cpp#L758-L774), you'll see that `TempNumSpaces` is only updated in the non-VT branch. As a result, the `_visibleCharCount` in the `COOKED_READ_DATA` class is not updated correctly, and the `DeleteCommandLine` method then doesn't fully clear the line when backspacing. It's possible this could be fixed just by updating `TempNumSpaces` with the distance that the cursor is moved in VT mode, but I don't know what other implications that would have. Also, the fact that we've got legacy code receiving VT-specific behavior is probably going to cause all sorts of other problems, because the two tab types are really quite different. That's potentially a bigger issue. Long term, I think it would be preferable if we could get rid of all of this VT-specific code in the `WriteCharsLegacy` method and just let the `AdaptDispatch` class have its own text writer that follows the VT rules (I'm hoping that's what #780 is going to achieve). Short term maybe we should be passing a flag to `WriteCharsLegacy` to say whether any VT behavior is allowed. In fact, the existing `WC_DELAY_EOL_WRAP` flag could possibly be repurposed for that.
Author
Owner

@j4james commented on GitHub (Dec 24, 2019):

Note that this is a conhost bug, and as far as I can tell, it only occurs when VT mode is enabled (i.e. you've set the VirtualTerminalLevel registry entry).

Actually this bit isn't quite true. If you're using the Windows Terminal, then you probably wouldn't need to set the registry entry to trigger the issue, because WT already sets the VT mode automatically (I think).

@j4james commented on GitHub (Dec 24, 2019): > Note that this is a conhost bug, and as far as I can tell, it only occurs when VT mode is enabled (i.e. you've set the _VirtualTerminalLevel_ registry entry). Actually this bit isn't quite true. If you're using the Windows Terminal, then you probably wouldn't need to set the registry entry to trigger the issue, because WT already sets the VT mode automatically (I think).
Author
Owner

@getkirill commented on GitHub (Dec 26, 2019):

Thanks everyone for your feedbacks! Bug isn't fixed yet, but anyway, THANKS!
(may contain broken english)

@getkirill commented on GitHub (Dec 26, 2019): Thanks everyone for your feedbacks! Bug isn't fixed yet, but anyway, THANKS! _(may contain broken english)_
Author
Owner

@zadjii-msft commented on GitHub (Dec 30, 2019):

The issue is that the WriteCharsLegacy method handles tabs differently in VT mode, and doesn't update the number of spaces written. If you look at the section of code where the tab is processed, you'll see that TempNumSpaces is only updated in the non-VT branch. As a result, the _visibleCharCount in the COOKED_READ_DATA class is not updated correctly, and the DeleteCommandLine method then doesn't fully clear the line when backspacing.

This might highly concern @miniksa

@zadjii-msft commented on GitHub (Dec 30, 2019): > The issue is that the `WriteCharsLegacy` method handles tabs differently in VT mode, and doesn't update the number of spaces written. If you look at [the section of code where the tab is processed](https://github.com/microsoft/terminal/blob/6f667f48ae109d4291cda1f8d4e977315c0dae8a/src/host/_stream.cpp#L758-L774), you'll see that `TempNumSpaces` is only updated in the non-VT branch. As a result, the `_visibleCharCount` in the `COOKED_READ_DATA` class is not updated correctly, and the `DeleteCommandLine` method then doesn't fully clear the line when backspacing. > This might highly concern @miniksa
Author
Owner

@ghost commented on GitHub (Feb 13, 2020):

:tada:This issue was addressed in #4289, which has now been successfully released as Windows Terminal Preview v0.9.433.0.🎉

Handy links:

@ghost commented on GitHub (Feb 13, 2020): :tada:This issue was addressed in #4289, which has now been successfully released as `Windows Terminal Preview v0.9.433.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.9.433.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#5579