Skip to content

Terminal: implement the alternate screen buffer (DEC mode 1049) - #2899

Open
insjang wants to merge 1 commit into
eclipse-platform:masterfrom
insjang:alt-screen
Open

Terminal: implement the alternate screen buffer (DEC mode 1049)#2899
insjang wants to merge 1 commit into
eclipse-platform:masterfrom
insjang:alt-screen

Conversation

@insjang

@insjang insjang commented Sep 3, 2026

Copy link
Copy Markdown

Full screen programs - vi, less, htop, and lately CLIs that draw their own UI - ask for the alternate screen with CSI ? 1049 h and give it back with CSI ? 1049 l. The emulator accepted the sequences and ignored them, so such a program drew over the shell's scrollback and left its last screen behind when it exited.

Switching to the alternate screen now saves the normal buffer and the cursor, clears the screen and caps the buffer at the screen height, so that scrolling drops the top line instead of growing history the alternate screen is not supposed to have. Switching back restores the saved buffer and cursor, lifts the cap again, and brings the buffer to the current width and at least the screen height, since the window may have been resized in the meantime: a narrower buffer made every write past its old margin throw, a shorter one put the top of the screen above its first line. The restored buffer tells its snapshots so the view redraws instead of keeping the program's last screen.

Modes 47 and 1047 are treated the same; 1048 (save/restore cursor alone) stays ignored. Asking for the screen one is already on is a no-op, as programs do ask twice.

Full screen programs - vi, less, htop, and lately CLIs that draw their
own UI - ask for the alternate screen with CSI ? 1049 h and give it
back with CSI ? 1049 l. The emulator accepted the sequences and ignored
them, so such a program drew over the shell's scrollback and left its
last screen behind when it exited.

Switching to the alternate screen now saves the normal buffer and the
cursor, clears the screen and caps the buffer at the screen height, so
that scrolling drops the top line instead of growing history the
alternate screen is not supposed to have. Switching back restores the
saved buffer and cursor, lifts the cap again, and brings the buffer to
the current width and at least the screen height, since the window may
have been resized in the meantime: a narrower buffer made every write
past its old margin throw, a shorter one put the top of the screen
above its first line. The restored buffer tells its snapshots so the
view redraws instead of keeping the program's last screen.

Modes 47 and 1047 are treated the same; 1048 (save/restore cursor
alone) stays ignored. Asking for the screen one is already on is a
no-op, as programs do ask twice.
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