Skip to content

vt: preserve semantic wraps across resize and reattach#919

Draft
takezoh wants to merge 2 commits into
charmbracelet:mainfrom
takezoh:agent/vt-semantic-scrollback
Draft

vt: preserve semantic wraps across resize and reattach#919
takezoh wants to merge 2 commits into
charmbracelet:mainfrom
takezoh:agent/vt-semantic-scrollback

Conversation

@takezoh

@takezoh takezoh commented Jul 16, 2026

Copy link
Copy Markdown

Summary

Preserve terminal soft-wrap boundaries in the VT screen and scrollback model, then use them to reflow retained content across resizes and reattachments.

Why

Physical terminal rows are not semantic lines. Once soft-wrap provenance is discarded, a narrow terminal snapshot cannot be reconstructed correctly when a wider client attaches: retained output stays permanently wrapped at the old width.

Changes

  • track soft-wrap provenance alongside visible and scrollback rows
  • rebuild logical lines and reflow them when the emulator width changes
  • preserve cursor position, pending-wrap state, wide cells, and truncated scrollback heads
  • add Emulator.ReattachSnapshot so reattachment emits hard boundaries as CRLF while leaving soft-wrap continuations unbroken
  • add regression coverage for narrow-to-wide reflow, wide cells, explicit line breaks, cursor mapping, alternate-screen snapshots, and capped scrollback

Impact

Consumers can rebuild a terminal for a new viewport without baking the previous client's width into retained history. Existing Scrollback.Line and Scrollback.Lines accessors remain available.

Checks

  • go test ./... in vt/
  • go test -race ./... in vt/
  • go vet ./... in vt/

takezoh added 2 commits July 16, 2026 07:00
Keep cells and row boundaries behind one mutation owner so erase, scroll, resize, and snapshot cannot observe stale parallel provenance. Separate alternate physical resize from primary reflow and make snapshots atomic and fallible.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant