Skip to content

Fix BCE hyperlink bleed, SU scrollback, DEL UTF-8 flush, and profile DECSC slots #25

Done

Description

@tony

Summary

Cross-checking libvt (#2, #8, #17) against Ghostty (11ed660d9 / vt-1.0.1), xterm (xterm-412), and live tmux 3.8a (17c016750) uncovered five universal VT bugs and five profile-specific divergences: _bce_pair() stamps active OSC 8 hyperlinks onto erased blank cells; SU (CSI Ps S) discards scrolled-off lines instead of pushing to primary scrollback when top == 0 and full-width; 0x7F (DEL) in GROUND fails to flush incomplete multi-byte UTF-8 sequences (gluing b"\xe2\x7f\x82\xac" into '€'); non-m CSI sequences with : subparameters execute instead of dropping; Formatter(OutputFormat.VT) emits IRM/DECOM/DECLRMM before drawing cells and omits wrapped=True row padding; and DECSTR, ?69, CSI 5;10 s, DECSTBM top > 0 history, and DECSC/?1049h cursor save slots differ between DEFAULT_PROFILE/XTERM_PROFILE and TMUX_PROFILE.

Reproduction

  1. Run the four minimal probes (BCE with active OSC 8, CSI 1 S on primary screen, 0x7F inside € UTF-8 bytes, and ESC 7 + ?1049h/?1049l + ESC 8 under TMUX_PROFILE):
uv run python -c 'from libvt import TMUX_PROFILE, Terminal; a = Terminal(rows=2, cols=8); a.feed(b"\x1b]8;;https://example.com\x07\x1b[42m\x1b[K\x1b]8;;\x07"); b = Terminal(rows=2, cols=8, scrollback=10); b.feed(b"rowA\r\nrowB\x1b[1S"); c = Terminal(rows=2, cols=8); c.feed(b"\xe2\x7f\x82\xac"); d = Terminal(rows=4, cols=8, profile=TMUX_PROFILE); d.feed(b"\x1b[3;1H\x1b7\x1b[3;3H\x1b[?1049h\x1b[?1049l\x1b8"); print("bce_link:", a[0, 3].hyperlink, "su_hist:", len(b.history), "del_utf8:", repr(c.lines[0]), "tmux_decsc:", (d.cursor.row, d.cursor.col))'

Expected

  • bce_link is None (BCE carries background color only, never OSC 8 hyperlinks).
  • su_hist is 1 ('rowA' saved to primary scrollback when top == 0 and horizontal margins are full-width, matching Ghostty Terminal.zig scrollUp and tmux 3.8a).
  • del_utf8 is '\ufffd\ufffd\ufffd' (0x7F DEL flushes incomplete â as U+FFFD before ignoring DEL), non-m CSI sequences containing : subparameters are ignored, DECSLRM partial scroll preserves wide glyphs wholly within [left, right] with text_used <= used, and Formatter(OutputFormat.VT) restores IRM/DECOM/DECLRMM after rendering cells while padding wrapped=True rows to cols.
  • On DEFAULT_PROFILE and XTERM_PROFILE, DECSTR (CSI ! p) resets only the VT510 soft-reset set (IRM, DECOM, DECAWM on, DECTCEM on, DECSTBM/DECSLRM, SGR/pen/DECSCA, G0–G3/GL/SS, pending_wrap, saved cursor, keeping ?1000–?1006/?2004 mouse and paste modes intact per Ghostty softReset), and primary DECSC shares the primary save slot with ?1049h while the alternate screen keeps its own separate DECSC slot (saving _single_shift too).
  • On TMUX_PROFILE, ?69 (DECLRMM) is disabled (CSI 5;10 s executes cursor save SCOSC), DECSTR remains a no-op, LF/IND/SU at bottom push DECSTBM top into primary history even when top > 0 (matching tmux screen-write.c), and DECSC (ESC 7) uses a separate save slot from ?1049h so tmux_decsc prints (2, 0).

Actual

bce_link: Hyperlink(uri='https://example.com', id='') su_hist: 0 del_utf8: '€' tmux_decsc: (2, 2).

Environment

Versions
  • libvt: #2 (0.1.0a0)
  • Python: 3.15.1
  • Reference tmux: 3.8a (17c016750)
  • Reference Ghostty: 11ed660d9 (vt-1.0.1)
  • OS: Linux x86_64

Proposal

Invariants

The invariants below are load-bearing; everything under Intent is open.

  • BCE erases (ED, EL, ECH, ICH, DCH, IL, DL, SU, SD, scroll linefeeds) never attach Hyperlink metadata to blanked cells.
  • Formatter(OutputFormat.VT).format_snapshot(snap) round-trips into a fresh Terminal of matching dimensions when IRM, DECOM, DECLRMM, or wrapped=True short/BCE rows are active.
  • Profile switches on Profile cleanly separate DEFAULT_PROFILE / XTERM_PROFILE (Ghostty / xterm semantics) from TMUX_PROFILE (tmux inner-pane semantics).

Intent (non-binding)

  • Add declrmm_enabled: bool = True, top_margin_scrolls_to_history: bool = False, and separate_alt_save_cursor: bool = False (naming open to match existing Profile fields) to Profile, with Profile.tmux() configuring declrmm_enabled=False, top_margin_scrolls_to_history=True, and separate DECSC vs ?1049h primary cursor slots.

Not doing

  • Enabling DECLRMM (?69) on TMUX_PROFILE (tmux does not implement left/right margin mode).

References

Activity

  1. added
    bug
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions