Repository navigation
Closed
Labels
bugSomething isn't working
Description
Summary
Differential testing of #2 against live tmux 3.8a and seeded grid-invariant fuzzing uncovered four edge-case state bugs in src/libvt/screen.py and src/libvt/terminal.py: DECSLRM vertical scrolling drops copied text from RowView.text, REP (CSI Ps b) repeats stale characters across cursor moves and charset switches, VS16 (U+FE0F) widens column cols - 1 past grid bounds when DECAWM (?7l) is reset, and DECALN (ESC # 8) leaves DECSTBM and DECOM active.
Reproduction
- Scroll text inside
DECSLRM(?69h, columns3..7) onto a blank row:
$ uv run python -c 'from libvt import Terminal; vt = Terminal(rows=4, cols=10); vt.feed(b"\x1b[?69h\x1b[3;7s\x1b[2;3HHELLO\x1b[1S\x1b[?69l"); print(vt.lines)'- Move the cursor or switch
G0to DEC Special Graphics between a printable character andREP(CSI b):
$ uv run python -c 'from libvt import Terminal; vt = Terminal(rows=3, cols=10); vt.feed(b"A\x1b[2;3H\x1b[4b"); vt2 = Terminal(rows=3, cols=10); vt2.feed(b"q\x1b(0\x1b[3b\x1b(B"); print("cup:", vt.lines, "acs:", vt2.lines)'- Feed
U+2764 U+FE0Fat column4of a5-column grid with autowrap disabled (CSI ? 7 l):
$ uv run python -c 'from libvt import Terminal, display_width; vt = Terminal(rows=2, cols=5); vt.feed(b"\x1b[?7l" + "abcd\u2764\ufe0f".encode()); print(repr(vt.screen[0].text), "width:", display_width(vt.screen[0].text))'Expected
- Step 1 prints
(' HELLO',)on row0and''on row1. - Step 2 prints
cup: ('A',)andacs: ('q',)because non-printable C0,ESC,CSI,OSC,DCS, andAPCactions invalidate_last_printed. - Step 3 keeps
display_width(vt.screen[0].text) <= 5(refusing 1-to-2 cell widening atcols - 1whenDECAWMis off). DECALN(ESC # 8) resetsDECSTBM/DECSLRMmargins to full screen, resetsDECOM(?6l), and homes the cursor to(0, 0).
Actual
- Step 1 prints
('', ' ')becauseScreen.scroll_up()andScreen.scroll_down()updatedst_row.usedwithout updatingdst_row.text_used, andclear_range()leaves staletext_usedon partial-row clears. - Step 2 prints
cup: ('A', ' AAAA')andacs: ('q───',)because_last_printedis cleared only onreset(). - Step 3 prints
'abcd❤️' width: 6on a5-column screen.
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
Proposal
Invariants
The invariants below are load-bearing; everything under Intent is open.
- For every row
r,row.text_usedaccurately bounds non-blank character data afterscroll_up,scroll_down, and partialclear_range, and total display width across0..cols - 1never exceedscols. REP(CSI Ps b) repeats only an immediately preceding graphic character without intervening control, escape, or cursor-movement sequences.DECALN(ESC # 8) resets scroll margins, clearsDECOM, clearspending_wrap, and homes the cursor to(0, 0).
Intent (non-binding)
- Recompute or advance
dst_row.text_usedinScreen.scroll_up()andScreen.scroll_down()partial-margin paths and tighten_Row.clear_range()when clearing acrosstext_used. - Clear
self._last_printed = ""onexecute,esc_dispatch,csi_dispatch(other thanREPitself before reading_last_printed),osc_dispatch,dcs_put/unhook, andapc_dispatch. - Guard
VS16cell widening in_try_extend_cluster()whenanchor_col == scr.cols - 1andnot self._modes.is_set(Mode.DECAWM).
Not doing
- Changing
VS16widening whenDECAWM(?7h) is enabled and the cluster wraps onto rowr + 1column0.
References
- Core(feat[vt]): Add sans-I/O VT engine, RLE grid, OSC 7501, input, and ADRs #2
Ghosttysrc/terminal/Terminal.zigdecalnandrep(e9dc690/vt-1.0.1): https://github.com/ghostty-org/ghostty/blob/e9dc690/src/terminal/Terminal.zigtmuxinput.c(72c20dc/3.8): https://github.com/tmux/tmux/blob/72c20dc/input.c
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
Grid(fix[margins]): Fix DECSLRM scroll and REP (#8)
Grid(fix[margins]): Fix DECSLRM scroll and REP (#8)
tony commentedon Nov 23, 2026
Resolved in #2 (
0c7ee41).