[PR #5683] [MERGED] Make sure that EraseAll moves the Terminal viewport #26415

Open
opened 2026-01-31 09:15:56 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/5683
Author: @zadjii-msft
Created: 5/1/2020
Status: Merged
Merged: 5/5/2020
Merged by: @undefined

Base: masterHead: dev/migrie/b/2J-should-work-too


📝 Commits (10+)

  • ff14bad This seems like it works as a test
  • 54a5bd2 Just from the test passing, I believe this will ship cmd.exe. Now time to actually play with it
  • 9583e04 Add the powershell case too
  • 841eff6 create the shim for powershell and Clear-Host as well
  • a4151c3 some doc comments I missed
  • f74d272 Make this only work for cmd.exe and powershell.exe
  • ed062ff pr comments
  • 2f61d55 Merge remote-tracking branch 'origin/master' into dev/migrie/b/3126-cls-shim
  • 89d6823 I think this works to passthrough 2J
  • a441a40 This is some code cleanup

📊 Changes

5 files changed (+139 additions, -7 deletions)

View changed files

📝 src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp (+125 -1)
📝 src/host/getset.cpp (+3 -3)
📝 src/host/getset.h (+1 -1)
📝 src/host/outputStream.cpp (+1 -1)
📝 src/terminal/adapter/adaptDispatch.cpp (+9 -1)

📄 Description

The Erase All VT sequence (^[[2J) is supposed to erase the entire
contents of the viewport. The way it usually does this is by shifting
the entirety of the viewport contents into scrollback, and starting the
new viewport below it.

Currently, conpty doesn't propagate that state change correctly. When
conpty gets a 2J, it simply erases the content of the connected
terminal's viewport, by writing over it with spaces. Conpty didn't
really have a good way of communicating "your viewport should move", it
only knew "the buffer is now full of spaces".

This would lead to bugs like #2832, where pressing ctrl+L in
bash would delete the current contents of the viewport, instead of
moving the viewport down.

This PR makes sure that when conpty sees a 2J, it passes that through
directly to the connected terminal application as well. Fortunately, 2J
was already implemented in the Windows Terminal, so this actually fixes
the behavior of ctrl+L/clear in WSL in the Terminal.

References

  • #4252 - right now this isn't the most optimal scenario, we're
    literally just printing a 2J, then we'll perform "erase line" height
    times. The erase line operations are all redundant at this point - the
    entire viewport is blank, but conpty doesn't really know that.
    Fortunately, #4252 was already filed for me to come through and
    optimize this path.

PR Checklist

Validation Steps Performed

  • ran tests
  • compared ctrl+L with its behavior in conhost
  • compared clear with its behavior in conhost

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/5683 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 5/1/2020 **Status:** ✅ Merged **Merged:** 5/5/2020 **Merged by:** [@undefined](undefined) **Base:** `master` ← **Head:** `dev/migrie/b/2J-should-work-too` --- ### 📝 Commits (10+) - [`ff14bad`](https://github.com/microsoft/terminal/commit/ff14bada3b58d91a680c6d22f7015147a7411230) This seems like it works as a test - [`54a5bd2`](https://github.com/microsoft/terminal/commit/54a5bd24100c57ec3f9e37c67d8e9a1e08b19756) Just from the test passing, I believe this will ship cmd.exe. Now time to actually play with it - [`9583e04`](https://github.com/microsoft/terminal/commit/9583e04605d6d4cb57d7f5df90674533ca499407) Add the powershell case too - [`841eff6`](https://github.com/microsoft/terminal/commit/841eff6281ce1353de671177407320b1d4707616) create the shim for powershell and Clear-Host as well - [`a4151c3`](https://github.com/microsoft/terminal/commit/a4151c320e879d24874d9b8a6baf23283b47dce2) some doc comments I missed - [`f74d272`](https://github.com/microsoft/terminal/commit/f74d272a8bc096e0dbf9804e8e22220855395073) Make this only work for cmd.exe and powershell.exe - [`ed062ff`](https://github.com/microsoft/terminal/commit/ed062ff46027003267e8a58904c88accd6d07c90) pr comments - [`2f61d55`](https://github.com/microsoft/terminal/commit/2f61d5565b523262722b10cfb83437e63f26c8be) Merge remote-tracking branch 'origin/master' into dev/migrie/b/3126-cls-shim - [`89d6823`](https://github.com/microsoft/terminal/commit/89d6823daa9ece91c21876354220a3c5f5695448) I think this works to passthrough 2J - [`a441a40`](https://github.com/microsoft/terminal/commit/a441a4010aaec7d0d615886dc8cbb52d7a0b9693) This is some code cleanup ### 📊 Changes **5 files changed** (+139 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/UnitTests_TerminalCore/ConptyRoundtripTests.cpp` (+125 -1) 📝 `src/host/getset.cpp` (+3 -3) 📝 `src/host/getset.h` (+1 -1) 📝 `src/host/outputStream.cpp` (+1 -1) 📝 `src/terminal/adapter/adaptDispatch.cpp` (+9 -1) </details> ### 📄 Description The Erase All VT sequence (`^[[2J`) is supposed to erase the entire contents of the viewport. The way it usually does this is by shifting the entirety of the viewport contents into scrollback, and starting the new viewport below it. Currently, conpty doesn't propagate that state change correctly. When conpty gets a 2J, it simply erases the content of the connected terminal's viewport, by writing over it with spaces. Conpty didn't really have a good way of communicating "your viewport should move", it only knew "the buffer is now full of spaces". This would lead to bugs like #2832, where pressing <kbd>ctrl+L</kbd> in `bash` would delete the current contents of the viewport, instead of moving the viewport down. This PR makes sure that when conpty sees a 2J, it passes that through directly to the connected terminal application as well. Fortunately, 2J was already implemented in the Windows Terminal, so this actually fixes the behavior of <kbd>ctrl+L</kbd>/`clear` in WSL in the Terminal. ## References * #4252 - right now this isn't the _most_ optimal scenario, we're literally just printing a 2J, then we'll perform "erase line" `height` times. The erase line operations are all redundant at this point - the entire viewport is blank, but conpty doesn't really know that. Fortunately, #4252 was already filed for me to come through and optimize this path. ## PR Checklist * [x] Closes #2832 * [x] I work here * [x] Tests added/passed * [n/a] Requires documentation to be updated ## Validation Steps Performed * ran tests * compared <kbd>ctrl+L</kbd> with its behavior in conhost * compared `clear` with its behavior in conhost --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:15:56 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#26415