-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
DCS sequences split across multiple "packets" can be corrupted by conpty #17117
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This is expected behavior. When the screen scrolls, the newly revealed line is meant to be filled with the active color attributes by default. You can control that behavior with |
I figured out the problem here. When performing a DCS sequence passthrough, the first thing we do is call So what's happening in this case is the initial part of the DCS gets passed through, then the console lock is released and the VT render engine proceeds with its paint. At this point there's nothing left for it paint, but that doesn't stop it from resetting the attributes in the "Prep Colors" step of As a quick hack fix, I made the |
After further investigation into why the VT render engine is sending that In theory, the terminal/src/renderer/vt/paint.cpp Lines 32 to 36 in 378b659
If not, that method returns terminal/src/renderer/vt/XtermEngine.cpp Lines 38 to 40 in 378b659
The other problem is that the In theory that could be fixed by checking whether the cursor position in the In short, I think we could fix this bug with the following:
This way we wouldn't need to mess with the console lock, so it seems like a safer approach. There might be edge cases that I'm missing though. |
After trying this out, I found there's an extra step required. When the |
When the VT render engine starts a paint operation, it first checks to see whether there is actually something to do, and if not it can end the frame early. However, the result of that check was being ignored, which could sometimes result in an unwanted `SGR` reset being written to the conpty pipe. This was particular concerning when passing through `DCS` sequences, because an unexpected `SGR` in the middle of the `DCS` string would cause it to abort early. This PR addresses the problem by making sure the `VtEngine::StartPaint` return value is appropriately handled in the `XtermEngine` class. ## Detailed Description of the Pull Request / Additional comments To make this work, I also needed to correct the `_cursorMoved` flag, because that is one of things that determines whether a paint is needed or not, but it was being set in the `InvalidateCursor` method at the start of ever frame, regardless of whether the cursor had actually moved. I also took this opportunity to get rid of the `_WillWriteSingleChar` method and the `_quickReturn` flag, which have been mostly obsolete for a long time now. The only place the flag was still used was to optimize single char writes when line renditions are active. But that could more easily be handled by testing the `_invalidMap` directly. ## Validation Steps Performed I've confirmed that the test case in issue #17117 is no longer aborting the `DCS` color table sequence early. Closes #17117 (cherry picked from commit 432dfcc) Service-Card-Id: 92501130 Service-Version: 1.21
When the VT render engine checks whether the cursor has moved in the `InvalidateCursor` method, it does so by comparing the origin of the given cursor region with the last text output coordinates. But these two values are actually from different coordinate systems, and when on a double-width line, the x text coordinate is half of the corresponding screen coordinate. As a result, the movement detection is sometimes incorrect. This PR fixes the issue by adding another field to track the last cursor origin in screen coordinates, so we have a meaningful value to compare against. ## References and Relevant Issues The previous cursor movement detection was added in PR #17194 to fix issue #17117. ## Validation Steps Performed I've confirmed that the test case from issue #17232 is now fixed, and the test case from issue #17117 is still working as expected. ## PR Checklist - [x] Closes #17232
Windows Terminal version
1.20.10822.0
Windows build number
10.0.19045.4291
Other Software
No response
Steps to reproduce
Run the following python script:
Expected Behavior
It should clear the screen and briefly make the background color red. It works as expected in OpenConsole.
Actual Behavior
In Windows Terminal, the background is left permanently red, and you can see the second half of the DCS sequence output on the screen:
0;2;0;0;0
.Looking at the debug tap, it appears that conpty is inserting an SGR reset sequence in the middle of the DCS stream (where the script sleeps for a bit). This seems similar to issue #16079, but that test case is now working correctly on the main branch, while this is still broken.
I haven't had a chance to git bisect it, so I'm not sure if it's a regression, but I wouldn't be surprised if it was always broken in some way (although possibly not obviously so). There may also be an element of timing involved, but I can reproduce the problem consistently with the script above.
The text was updated successfully, but these errors were encountered: