-
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
C0 characters in screen buffer are incorrectly interpreted as controls by conpty #4363
Comments
Yep, absolutely. This is pretty bad, but it's something we've kicked down the road a bit. I was secretly hoping we could add 0x2400 to each one when we render it and get the Control Picture... I had written "this is the actual root cause of #1965", but then I read the history and I think we just never filed the followup bug for this, and to boot I realized that you had filed it. 😁 |
#1965 (comment) and #1965 (comment) for context |
Ah, that's the issue I was looking for. I knew we'd discussed this somewhere before, but all I could find was PR #1964 (which I thought at the time would have solved the problem, but clearly not in all situations). As for how we fix it, if we want WT to be "compatible" with the legacy console, then I would have thought conpty could simply translate these characters to the Unicode replacement character (U+FFFD)? If that's the glyph they produce in conhost, then surely that's what you'd want to see in WT too. |
When using the legacy console APIs, it's possible to write arbitrary codepoints into the buffer. If any of those codepoints are in the C0 or C1 range, and the buffer contents are forwarded over conpty, they can end up mistakenly interpreted as controls by the connected terminal. This PR fixes that issue by converting any C0 and C1 codepoints in the buffer into printable glyphs before forwarding them over conpty. I've used the C0 glyphs from the DOS 437 codepage and just a `?` for the C1 codepoints, since that's what you would typically have seen in the v1 console with a raster font. Although this doesn't address the main problem in #16410, it should at least fix the rendering issues they're seeing when running their app in Windows Terminal. I've confirmed that the test case in #4363 now looks the same in Windows Terminal as it does in conhost, and I've tested the Windows version of the terminal game [Gorched], and confirmed that it now works correctly in Window Terminal. [Gorched]: https://github.com/zladovan/gorched Closes #4363 Closes #6265 (cherry picked from commit 563b731) Service-Card-Id: 92001662 Service-Version: 1.20
When using the legacy console APIs, it's possible to write arbitrary codepoints into the buffer. If any of those codepoints are in the C0 or C1 range, and the buffer contents are forwarded over conpty, they can end up mistakenly interpreted as controls by the connected terminal. This PR fixes that issue by converting any C0 and C1 codepoints in the buffer into printable glyphs before forwarding them over conpty. I've used the C0 glyphs from the DOS 437 codepage and just a `?` for the C1 codepoints, since that's what you would typically have seen in the v1 console with a raster font. Although this doesn't address the main problem in #16410, it should at least fix the rendering issues they're seeing when running their app in Windows Terminal. I've confirmed that the test case in #4363 now looks the same in Windows Terminal as it does in conhost, and I've tested the Windows version of the terminal game [Gorched], and confirmed that it now works correctly in Window Terminal. [Gorched]: https://github.com/zladovan/gorched Closes #4363 Closes #6265 (cherry picked from commit 563b731) Service-Card-Id: 92001661 Service-Version: 1.19
Environment
Steps to reproduce
Compile the follow C++ program, and then run the resulting executable from a cmd shell in the Windows Terminal.
Expected behavior
The
WriteConsoleOutputCharacterW
api writes directly to the screen buffer, without attempting to process any control characters. I would thus expect the text message to be output entirely on the first line of the screen buffer, with theESC
andLF
control characters output as glyphs, and not interpreted. This is what it looks like in a conhost cmd shell:Note that the
ENABLE_VIRTUAL_TERMINAL_PROCESSING
mode should have no effect on this API. I've only turned it on to make sure the code is running under the same conditions in conhost as it is in WT (which enables VT mode by default).Actual behavior
In the Windows Terminal, the
ESC
andLF
characters are interpreted as control characters instead of being output as glyphs. As a result, you get an escape sequence changing the text color to red, and the text will be output over multiple lines.Depending on timing, you can also end up with other parts of the screen being redrawn incorrectly, as the terminal cursor position is now out of sync with where the conhost thinks it is (notice part of the copyright message being redrawn two lines down in red).
The text was updated successfully, but these errors were encountered: