Skip to content

Preserve pending_wrap and wide glyphs across Screen.resize() #4

Closed

Description

@tony

Summary

Screen.resize() and Screen._reflow_primary() in src/libvt/screen.py (#2) clear _pending_wrap = False unconditionally without checking whether dimensions changed or advancing the logical insertion column when widening. Resizing 4x2 to 4x2 after writing ABCD causes the next byte E to overwrite D (ABCE), and widening 4x2 to 8x2 after writing AB界 causes E to overwrite the wide glyph 界 (ABE).

Reproduction

  1. Run a same-size 4x2 resize and a 4x2 to 8x2 wide-character resize on #2:
$ uv run python -c 'from libvt import TMUX_PROFILE, Terminal; vt = Terminal(rows=2, cols=4, profile=TMUX_PROFILE); vt.feed(b"ABCD"); vt.resize(rows=2, cols=4); vt.feed(b"E"); print("same:", vt.lines, vt.cursor); vt2 = Terminal(rows=2, cols=4, profile=TMUX_PROFILE); vt2.feed("AB界".encode()); vt2.resize(rows=2, cols=8, reflow=True); vt2.feed(b"E"); print("wide:", vt2.lines, vt2.cursor)'

Expected

  • Same-size resize (4x2 to 4x2) preserves _pending_wrap = True across every profile so E wraps onto the second row (('ABCD', 'E'), 0-based Cursor(row=1, col=1, pending_wrap=False)).
  • Widening (4x2 to 8x2) with reflow=True advances the deferred wrap past the final cell (including both columns of a width-2 glyph) so ABCD + E produces ('ABCDE',) and AB界 + E produces ('AB界E',) at 0-based column 5.
  • Widening (4x2 to 8x2) under non-reflow xterm (snapshots repo, ctlseqs, xterm-412 tag) semantics (reflow=False on XTERM_PROFILE) retains pending_wrap = True at the old margin column 3 so E wraps to row 1 (('ABCD', 'E')).

Actual

same: ('ABCE',) Cursor(row=0, col=3, ..., pending_wrap=True) and wide: ('ABE',) Cursor(row=0, col=3, ..., pending_wrap=False).

Environment
  • libvt: #2 (feat/v2-architecture, 0.1.0a0)
  • Python: 3.15.0 (unicodedata 17.0.0)
  • Reference tmux: 3.8a (tmux -f /dev/null)
  • OS: Linux x86_64
Affected code in src/libvt/screen.py (#2)
self._cur_row = max(0, min(rows - 1, new_cur_abs - hist_cut))
self._cur_col = max(0, min(cols - 1, new_cur_col))
self._pending_wrap = False

Proposal

Invariants

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

  • Calling resize(rows=r, cols=c) when (r, c) equals current (rows, cols) preserves cursor coordinates, pending_wrap, DECSC saved cursor state, and scroll margins across all profiles (while still permitting ?2026 hold recovery on Terminal.resize()).
  • Resizing never leaves an orphaned WidthRole.WIDE lead cell without its SPACER_TAIL or sums any row's cell display widths past cols.
  • ScreenSet.resize() continues to pass reflow=False to self.alternate so alternate-screen TUI grids never reflow.

Intent (non-binding)

  • When cols == old_cols and only rows changes, preserve _pending_wrap unless vertical clamping moves the cursor off its line.
  • In _reflow_primary(), treat (cur_row, old_cols - 1, pending_wrap=True) (or (cur_row, old_cols - 2, pending_wrap=True) when WidthRole.WIDE occupies columns old_cols - 2 .. old_cols - 1) as pointing at logical offset old_cols after the row's content, matching Ghostty (repo, libghostty-vt docs, vt-1.0.1 tag) Screen.resize and tmux (3.8 release, man page).
  • On non-reflow widening (reflow=False), retain _pending_wrap = True at _cur_col (3) so the next printable scalar wraps onto the next row, matching xterm ScreenResize.

Not doing

  • Translating tmux's GRID_FLAG_TAB multi-cell tab reflow internals into _Row.

References

Activity

  1. added
    bug
    on Nov 22, 2026
  2. tony commented on Nov 23, 2026

    @tony
    MemberAuthor

    Resolved in #2 (0c7ee41).

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