Skip to content

Terminal: keep the screen in the history when it is cleared - #2973

Open
insjang wants to merge 2 commits into
eclipse-platform:masterfrom
insjang:ed2-scrollback
Open

insjang wants to merge 2 commits into
eclipse-platform:masterfrom
insjang:ed2-scrollback

Conversation

@insjang

@insjang insjang commented Sep 28, 2026

Copy link
Copy Markdown

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 200 in 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:

  • Blank lines at the bottom of the screen are not moved into the history, so clearing an empty or half-empty screen does not pad the history with blank lines.
  • The cursor does not move, as ED requires.
  • Where the buffer is at its maximum, the oldest lines make way. Where the buffer is capped at the screen height nothing is kept, so a screen with no history stays without one.
  • CSI 3 J still clears the history, so 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.

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,
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 change to erasing alters the bundle's content, and the build
compares it against the 4.41 release, where 1.1.200 already exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant