Skip to content

vt: clamp stale scroll margins to screen bounds#908

Open
takezoh wants to merge 2 commits into
charmbracelet:mainfrom
takezoh:fix/vt-clamp-stale-margins
Open

vt: clamp stale scroll margins to screen bounds#908
takezoh wants to merge 2 commits into
charmbracelet:mainfrom
takezoh:fix/vt-clamp-stale-margins

Conversation

@takezoh

@takezoh takezoh commented Jul 5, 2026

Copy link
Copy Markdown

Summary

Clamp horizontal and vertical scroll margins to the current screen bounds when they are stored on Screen.

Why

A terminal app can emit DECSTBM or DECSLRM using a stale size while a resize is racing through the PTY. Without clamping, Screen.scroll can retain an out-of-bounds bottom/right edge, and a later reverse-index / scroll operation can drive InsertLineArea past the buffer bounds.

Changes

  • clamp setHorizontalMargins to [0,width]
  • clamp setVerticalMargins to [0,height]
  • ignore degenerate regions after clamping, matching existing left >= right / top >= bottom behavior
  • add regression tests for stale DECSTBM, stale DECSLRM, and the reverse-index crash path

Test

  • go test ./... in vt/

@takezoh
takezoh marked this pull request as ready for review July 5, 2026 07:50
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