Understand why the PTY might delete and then re-add spaces on certain lines #7514

Closed
opened 2026-01-31 01:05:51 +00:00 by claunia · 0 comments
Owner

Originally created by @DHowett-MSFT on GitHub (Apr 20, 2020).

Notes from #5398

SPACES REMOVED WHEN:
* line was not wrapped

AND

* It is optimal to prefer ECH/EL
* We are not on a new bottom line
* We did not clear all this frame
OR
* We cleared all this frame
OR
* It is a new bottom line and we are on it

SPACES RE-ADDED WHEN:
* It is not optimal to prefer ECH/EL
OR
* It is a new bottom line
OR
* We cleared all this frame

AND
* It is a new bottom line and we are on it
* The line had spaces at the end.
* We deleted the spaces previously <<< NEW IN #5398

Originally posted by @DHowett-MSFT in https://github.com/microsoft/terminal/pull/5398#issuecomment-616748070

While we're looking at this, we'll want to investigate how to consolidate the space add/remove logic so that we can make maximal use of the buffer already passed to us (like: write it out in full if it has spaces we want to keep, etc.)

Notes from @zadjii-msft

I can't remember tbh. This screams organic growth to me - I think we first just decided to do ECH and removing spaces, when we didn't have wrapping (and spaces didn't matter). Then we did some deferring the cursor movement & not erasing optimizations in 20H1, which added cases where we wouldn't ECH. Now we're adding cases where we still need the spaces. I suppose if we'd written it from scratch now, accounting for wrapping, we'd do it better.

I'd TODO it tbh.

I bet we were trying to optimize out the cursor positioning that we'd do after a new line is printed. If we did optimize that scenario, and used ECH to erase some spaces, we also used CUF to move the cursor. However, if we couldn't do that, we'd still want to leave the cursor in the right place...

yea we probably should have just not removed them in the first place.

Originally created by @DHowett-MSFT on GitHub (Apr 20, 2020). Notes from #5398 ``` SPACES REMOVED WHEN: * line was not wrapped AND * It is optimal to prefer ECH/EL * We are not on a new bottom line * We did not clear all this frame OR * We cleared all this frame OR * It is a new bottom line and we are on it SPACES RE-ADDED WHEN: * It is not optimal to prefer ECH/EL OR * It is a new bottom line OR * We cleared all this frame AND * It is a new bottom line and we are on it * The line had spaces at the end. * We deleted the spaces previously <<< NEW IN #5398 ``` _Originally posted by @DHowett-MSFT in https://github.com/microsoft/terminal/pull/5398#issuecomment-616748070_ While we're looking at this, we'll want to investigate how to consolidate the space add/remove logic so that we can make maximal use of the buffer already passed to us (like: write it out in full if it has spaces we want to keep, etc.) Notes from @zadjii-msft > I can't remember tbh. This screams organic growth to me - I think we first just decided to do ECH and removing spaces, when we didn't have wrapping (and spaces didn't matter). Then we did some deferring the cursor movement & not erasing optimizations in 20H1, which added cases where we wouldn't ECH. Now we're adding cases where we still need the spaces. I suppose if we'd written it from scratch now, accounting for wrapping, we'd do it better. > > I'd TODO it tbh. > I bet we were trying to optimize out the cursor positioning that we'd do after a new line is printed. If we did optimize that scenario, and used ECH to erase some spaces, we also used CUF to move the cursor. However, if we couldn't do that, we'd still want to leave the cursor in the right place... > > yea we probably should have just not removed them in the first place.
claunia added the Issue-TaskNeeds-Tag-FixProduct-ConptyPriority-2Area-CodeHealth labels 2026-01-31 01:05:52 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7514