Repository navigation
Closed
Labels
bugSomething isn't working
Description
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
- Run a same-size
4x2resize and a4x2to8x2wide-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 (
4x2to4x2) preserves_pending_wrap = Trueacross every profile soEwraps onto the second row (('ABCD', 'E'), 0-basedCursor(row=1, col=1, pending_wrap=False)). - Widening (
4x2to8x2) withreflow=Trueadvances the deferred wrap past the final cell (including both columns of a width-2 glyph) soABCD+Eproduces('ABCDE',)andAB界+Eproduces('AB界E',)at 0-based column5. - Widening (
4x2to8x2) under non-reflow xterm (snapshots repo, ctlseqs, xterm-412 tag) semantics (reflow=FalseonXTERM_PROFILE) retainspending_wrap = Trueat the old margin column3soEwraps to row1(('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(unicodedata17.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 = FalseProposal
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,DECSCsaved cursor state, and scroll margins across all profiles (while still permitting?2026hold recovery onTerminal.resize()). - Resizing never leaves an orphaned
WidthRole.WIDElead cell without itsSPACER_TAILor sums any row's cell display widths pastcols. ScreenSet.resize()continues to passreflow=Falsetoself.alternateso alternate-screen TUI grids never reflow.
Intent (non-binding)
- When
cols == old_colsand onlyrowschanges, preserve_pending_wrapunless 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)whenWidthRole.WIDEoccupies columnsold_cols - 2 .. old_cols - 1) as pointing at logical offsetold_colsafter the row's content, matching Ghostty (repo, libghostty-vt docs, vt-1.0.1 tag)Screen.resizeand tmux (3.8 release, man page). - On non-reflow widening (
reflow=False), retain_pending_wrap = Trueat_cur_col(3) so the next printable scalar wraps onto the next row, matchingxtermScreenResize.
Not doing
- Translating
tmux'sGRID_FLAG_TABmulti-cell tab reflow internals into_Row.
References
- Core(feat[vt]): Add sans-I/O VT engine, RLE grid, OSC 7501, input, and ADRs #2
Ghosttysrc/terminal/Screen.zig(e9dc690/vt-1.0.1): https://github.com/ghostty-org/ghostty/blob/e9dc690/src/terminal/Screen.zigxtermscreen.c(xterm-412): https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-412/screen.c
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
Screen(fix[resize]): Preserve pending_wrap on resize (#4)
tony commentedon Nov 23, 2026
Resolved in #2 (
0c7ee41).