Skip to content
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

ConPTY emits nothing to clear the right side when downsizing #8880

Closed
o-sdn-o opened this issue Jan 25, 2021 · 5 comments
Closed

ConPTY emits nothing to clear the right side when downsizing #8880

o-sdn-o opened this issue Jan 25, 2021 · 5 comments
Labels
Issue-Question For questions or discussion Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Product-Conpty For console issues specifically related to conpty Resolution-Answered Related to questions that have been answered

Comments

@o-sdn-o
Copy link

o-sdn-o commented Jan 25, 2021

Environment

Windows build number: 10.0.19042.746
Windows Terminal version (if applicable):

Any other software: My own ConPTY-based terminal emulator

I am making my own terminal multiplexer using ConPTY.
ConPTY instances serve as consoles for multiplexer applications. The dimensions of these consoles can be changed by mouse. Each time the console is resized, the ConPTY instance is resized at the same time, which triggers it to redraw its buffer contents.

Using ConPTY in my own terminal emulator, it is impossible to know that visible lines should be truncated when the ConPTY is reduced in size. ConPTY emits nothing to clear the right side when downsizing.
May be related to #5800

Actual behavior

The picture below shows the multiplexer, where the ConPTY consoles are located on the left, and on the right is a window with the output of everything that ConPTY emits when redrawn (top part is raw text, bottom part is code points)

Console lines are doubled in case my built-in terminal wraps the lines by itself:

ConPTY with wrapping

In the case when my built-in terminal has horizontal scrolling enabled, the lines are simultaneously continued and wrapped (since ConPTY wraps lines):

ConPTY without wrapping

It looks like ConPTY does not take into account that the external buffer may be larger and there may be fragments left when the ConPTY is reduced in size.
A possible solution would be to add \e[m\e[K before \r\n at the end of each line to indicate that this is an explicit end of the line.

CSI Ps K Erase in Line (EL), VT100.

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jan 25, 2021
@zadjii-msft
Copy link
Member

So, for the record, I've been through madness and back trying to get this just right. You might be interested in #4200, and the PRs and issues linked to that one. I have notes scattered throughout. Be aware, this way leads madness.

It looks like ConPTY does not take into account that the external buffer may be larger and there may be fragments left when the ConPTY is reduced in size.

If that's the end goal, then I think the best plan is to just not decrease the ConPTY size. ConPTY assumes that the end terminal buffer is exactly as large as conpty is. So make conpty exactly as large as you want your buffer. If you want to have your buffer be larger than the viewport, go for it. That's how I'm planning on addressing #1860.

Trying to keep external buffers in sync with the console buffer is really annoying, and there's not a good way to do it. The problem comes from the fact that there fundamentally is a buffer that conpty must maintain for the client apps to be able to query, but it must also keep that buffer in sync with the terminal emulator. Unfortunately, the emulator may resize itself while conpty is reacting to a previous resize attempt, and now conpty is trying to render into a space that's different dimensions. WT gets around this by manually telling conpty "I know what I'm doing, don't repaint on a resize", then manually reflowing the WT buffer exactly the same way conhost would.

So yeah, good luck 😄

@zadjii-msft zadjii-msft added Issue-Question For questions or discussion Product-Conpty For console issues specifically related to conpty Resolution-Answered Related to questions that have been answered labels Jan 25, 2021
@o-sdn-o
Copy link
Author

o-sdn-o commented Jan 25, 2021

So make conpty exactly as large as you want your buffer.

my problem is that I don't have a buffer per se, only strings, and the client can emit infinitely (uint32_t) long strings (and use horizontal scrolling or my own wrapping)

@o-sdn-o o-sdn-o closed this as completed Jan 25, 2021
@DHowett
Copy link
Member

DHowett commented Jan 25, 2021

Right, but... having no bounded size is incompatible with terminal emulation. Even when you're hosting processes on Linux, they can request the size in both character cells and pixels with TIOCGWINSZ. There's a signal for the window size changing and everything. Unfortunately, there just isn't precedent for boundless pseudoterminals.

@o-sdn-o
Copy link
Author

o-sdn-o commented Jan 25, 2021

they can request the size in both character cells and pixels with TIOCGWINSZ. There's a signal for the window size changing and everything

The internal structure of my terminal does not have any width limitation. To implement this, I added a new concept to the "viewport" concept: "right oversize" (+ "left oversize" for RTL). Applications that ask the terminal about its size receive a "viewport" in response. The process of stacking text in the terminal takes into account the "oversize".

unlim width

@o-sdn-o
Copy link
Author

o-sdn-o commented Jan 25, 2021

ConPTY works as expected if I force the use of OpenConsole.exe (from the latest main) instead of conhost.exe that shipped with Windows.

What I missed is that ConPTY is updated independently of Windows Terminal. Now I will rely on the compiled OpenConsole.exe. Sorry for the inattention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Question For questions or discussion Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Product-Conpty For console issues specifically related to conpty Resolution-Answered Related to questions that have been answered
Projects
None yet
Development

No branches or pull requests

3 participants