Repository navigation
Terminal: keep the screen in the history when it is cleared - #2973
Conversation
f0b99f9 to
0760996
Compare
|
Related work, so the two are not mistaken for duplicates: #2764 by @vogella (for #2680, Codex CLI cannot scroll back) moves the line displaced at the top of a scroll region into the history. This PR covers a different path, erase in display (CSI 2 J), which ConPTY sends at the start of every connection and which programs send to clear the screen. Both feed the history and they complement each other. They touch nearby code in VT100EmulatorBackend, so whichever lands second may need a small rebase, which I am happy to do. |
0760996 to
ea4ad3c
Compare
|
Rebased on master, one commit, ea4ad3c; the version bump is no longer needed, master is at 1.1.300 already. All terminal tests pass. How to test, in a runtime Eclipse with this org.eclipse.terminal.control, Terminal view:
Unit tests: testEraseAll (now expects the screen in the history), testEraseAllKeepsTheScreenInHistory (blank lines at the bottom, the cursor; TerminalTextDataStore and TerminalTextData) and testClearScreenKeepsItInHistory (the sequence ConPTY sends, through the emulator). |
There was a problem hiding this comment.
🟡 Changes recommended
Buffer growth leaves the model cursor at its old absolute line, so CSI 2 J can move the visible cursor to the wrong row or into history unless its screen-relative position is restored.
1 open issue
What changed in this PR
This PR preserves Eclipse terminal output in history when CSI 2 J clears the screen, preventing output loss during ConPTY reconnections on Windows.
Changes:
- Moves screen contents into history before erasing, excluding trailing blank lines.
- Updates backend tests for history retention, buffer limits, and cursor position.
- Adds an emulator regression test for the ConPTY startup sequence.
| File | Description |
|---|---|
| terminal/tests/org.eclipse.terminal.test/src/org/eclipse/terminal/internal/emulator/VT100EmulatorTest.java | Tests history preservation through the ConPTY clear-screen sequence. |
| terminal/tests/org.eclipse.terminal.test/src/org/eclipse/terminal/internal/emulator/VT100EmulatorBackendTest.java | Updates erase expectations and tests blank-line trimming and cursor preservation. |
| terminal/bundles/org.eclipse.terminal.control/src/org/eclipse/terminal/internal/emulator/VT100EmulatorBackend.java | Saves screen contents to history before clearing the display. |
Review effort: Balanced
ea4ad3c to
db6cafb
Compare
|
Fixed in db6cafb: after the lines go into the history the cursor is set again on its row of the screen, so the model's cursor follows; testEraseAllKeepsTheScreenInHistory now checks it (7, was 4). |
|
This depends on #2899. On master the alternate screen is still ignored (modes 47/1047/1049), so full screen programs draw on the main buffer and every |
456cf31 to
380c638
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Screen clearing retains a wrapped spaces-only row without following its continuation, causing copied text across the history boundary to join old output with new text without a newline.
1 open issue
2 resolved since last review
Review effort: Balanced
380c638 to
da26d19
Compare
Erase in display (CSI 2 J) now moves what is on the screen into the history before erasing it, as Windows Terminal and VTE do, instead of destroying it. Blank lines at the bottom of the screen are left out, except the rows a line runs on to, so the history ends where a line ends, and the cursor does not move. Where the buffer cannot grow, the oldest lines make way; on a buffer capped at the screen height nothing is kept, as before. This matters most on Windows: ConPTY starts every connection with CSI 2 J CSI H, so reconnecting a terminal erased as many lines of the previous session as the screen was high, and a program that clears the screen took the user's last screen of output with it. CSI 3 J still clears the history, so "clear" empties everything as it did. The cursor stays on its row of the screen, in the model as well, however far the screen moved down the buffer. The alternate screen (modes 47, 1047 and 1049) is capped at the screen height and keeps no history, so a program redrawing there with CSI 2 J does not push its old frames into the scrollback: they are gone when the normal screen comes back.
da26d19 to
b66ec72
Compare

Erase in display (CSI 2 J) destroyed what was on the screen. It now moves it into the history first, the way Windows Terminal and VTE handle it, and then erases.
Why it matters. On Windows the local terminal runs through ConPTY, and ConPTY starts every connection with CSI 2 J followed by CSI H. Reconnecting a terminal therefore erased as many lines of the previous session as the screen was high: after
seq 1 200in a 31-line terminal, a reconnect kept only 1 to 171. The same happens whenever a program clears the screen, taking the user's last screen of output with it. This was captured from a real ConPTY session (wsl.exe) and replayed through the emulator; the loss is the same on current master.Details:
clear(CSI H CSI 2 J CSI 3 J) empties everything as before.xterm itself erases without keeping the screen; this follows the terminals most users on Windows and Linux compare Eclipse's terminal with.
Tests: testEraseAll now expects the screen in the history; testEraseAllKeepsTheScreenInHistory covers the blank lines at the bottom and the cursor, on both TerminalTextDataStore and TerminalTextData; testClearScreenKeepsItInHistory runs the sequence ConPTY sends through the emulator. All three fail without the change.