Repository navigation
Closed
Labels
bugSomething isn't working
Description
Summary
Terminal._erase_display() in src/libvt/terminal.py (#2) routes CSI 3 J (ED 3, Erase Saved Lines) into elif mode in (2, 3): and finishes with self._set_cursor(scr, c_row, c_col, pending_wrap=False), wiping all visible viewport rows (keep1, keep2) and clearing pending_wrap instead of erasing scrollback history alone.
Reproduction
- Scroll
oldinto history withkeep1andkeep2on a5x2viewport and feedCSI 3 J:
$ uv run python -c 'from libvt import Terminal; vt = Terminal(rows=2, cols=5, scrollback=100); vt.feed(b"old\r\nkeep1\r\nkeep2\x1b[3J"); print("history:", [r.text for r in vt.history], "lines:", vt.lines, "wrap:", vt.cursor.pending_wrap)'Expected
- Primary screen
CSI 3 Jclears scrollback (history: []) while leaving visible rows('keep1', 'keep2'), cursor coordinates, andpending_wrap=Trueuntouched, matching xterm (ctlseqs, xterm-412), Ghostty (vt-1.0.1), and tmux (3.8). - Alternate screen (
?1049h)CSI 3 Jleaves visible alternate cells untouched and follows profile policy on primary history:TMUX_PROFILEandXTERM_PROFILEclear primary scrollback (matchingtmuxscreen_alternate_onretaining history ins->gridandxtermutil.c), whileDEFAULT_PROFILEclears onlyactive.clear_history()(preserving primary scrollback, matchingGhosttyeraseDisplay(.scrollback)).
Actual
history: [] lines: () wrap: False — visible rows keep1 and keep2 are erased (matching Linux console_codes(4) and pyte's how in (2, 3) bug) and pending_wrap is cleared.
Environment
libvt:#2(feat/v2-architecture,0.1.0a0)- Python:
3.15.0(unicodedata17.0.0) - Reference
tmux:3.8a(tmux -f /dev/null) - OS: Linux
x86_64
Affected code in src/libvt/terminal.py (#2)
elif mode in (2, 3):
for r in range(scr.rows):
scr._rows[r].clear_range(0, scr.cols, bce_w, bce_e, selective=selective)
if mode == 3 and not selective:
scr.clear_history()
self._notify_erase(Rect(0, 0, scr.rows, scr.cols), cause)Proposal
Invariants
The invariants below are load-bearing; everything under Intent is open.
CSI 3 J(mode == 3,selective=False) never mutates visible_rows, cursor(row, col), orpending_wrap.DECSED 3(CSI ? 3 J,selective=True) does not wipe visible rows or unguarded history unless specified.
Intent (non-binding)
- Separate
elif mode == 2:fromelif mode == 3 and not selective:in_erase_display(), returning beforeself._set_cursor(scr, c_row, c_col, pending_wrap=False)whenmode == 3. - Add a profile attribute (such as
ed3_clears_primary_on_alt: bool,FalseonDEFAULT_PROFILEandTrueonXTERM_PROFILEandTMUX_PROFILE) controlling whetherCSI 3 Jon?1049hclearsself._screens.primary.clear_history().
Not doing
- Altering
CSI 2 J(ED 2) orCSI 22 Jscroll-complete behavior.
References
- Core(feat[vt]): Add sans-I/O VT engine, RLE grid, OSC 7501, input, and ADRs #2
tmuxinput.candscreen.c(72c20dc/3.8): https://github.com/tmux/tmux/blob/72c20dc/input.c and https://github.com/tmux/tmux/blob/72c20dc/screen.cGhosttysrc/terminal/Terminal.zig(e9dc690/vt-1.0.1): https://github.com/ghostty-org/ghostty/blob/e9dc690/src/terminal/Terminal.zigxtermutil.c(xterm-412): https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-412/util.c
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
Terminal(fix[erase]): Keep viewport on CSI 3 J (#6)
Terminal(fix[erase]): Keep viewport on CSI 3 J (#6)
tony commentedon Nov 23, 2026
Resolved in #2 (
0c7ee41).