Skip to content

Screen leaves history[-1].wrapped set after in-place row-0 erase #153

In review

Description

@tony

Summary

When a soft-wrapped line spills its leading segment into scrollback (history[-1].wrapped == True) and its continuation on viewport row 0 is erased in place via CSI 2 J (ED 2), CSI 0 J at (0, 0), CSI 1 J, or CSI 2 K (EL 2), Screen clears row 0's cells without clearing history[-1].wrapped. Subsequent Terminal.resize(..., reflow=True) and serialize_vt_snapshot() calls treat post-clear text at (0, 0) as a soft-wrapped continuation of the pre-clear scrollback row and splice them together ('abcdefghFresh').

Reproduction

  1. Feed an 18-column soft-wrapped line into an 8x2 Terminal under DEFAULT_PROFILE (ed2_scrolls_primary_to_history=False), erase the screen in place with \x1b[2J\x1b[H, write Fresh, and widen or snapshot with a scrubber:
$ uv run python -c '
import libvt
from libvt.testing import serialize_vt_snapshot

term = libvt.Terminal(rows=2, cols=8)
term.feed(b"abcdefghijklmnopqr\x1b[2J\x1b[HFresh")
print("history:", [(r.text, r.wrapped) for r in term.screen.history])
print(serialize_vt_snapshot(term, scrubbers=[(r"Fresh", "OK")]))
term.resize(rows=2, cols=16, reflow=True)
print("after widen:", term.screen.lines)
'

Expected

Erasing row 0 from column 0 severs the incoming soft-wrap from history[-1] (wrapped == False), matching Ghostty's Screen.clearRows / cursorResetWrap (wrap_continuation = false), so Fresh remains an independent line at row 0 across both serialize_vt_snapshot() and Terminal.resize(..., reflow=True):

history: [('abcdefgh', False)]
size=8x2 cursor=(0,2,vis=True) alt=False modes=[]
┌────────┐
│OK      │
│        │
└────────┘
after widen: ('Fresh', '')

Actual

history[-1].wrapped stays True after \x1b[2J, pulling abcdefgh into serialize_vt_snapshot() and splicing 'abcdefghFresh' onto row 0 during resize(..., reflow=True):

history: [('abcdefgh', True)]
size=8x2 cursor=(1,2,vis=True) alt=False modes=[]
┌────────┐
│abcdefgh│W
│OK      │
└────────┘
after widen: ('abcdefghFresh', '')

Environment

Versions
  • libvt: 0.0.1a5 (587227c87c71f57bbc7095a5e71b1ed9df6458a0)
  • Python: 3.14.9
  • OS: Linux (x86_64)

References

Activity

  1. added
    bug
    p1
    on Dec 2, 2026
  2. tony commented on Dec 3, 2026

    @tony
    MemberAuthor

    In the local 8×2 ED2 replay, widening to 16×2 produced ('Fresh', '') at cursor (0, 5) under the default profile. The prior abcdefgh row stayed in scrollback with its wrap flag clear. Compiled Ghostty VT 1.0.2 instead retained the incoming wrap and produced abcdefghFresh. The local Ghostty preset reproduced that output with whole and bytewise input. Related PR #149

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

    bugp1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions