Skip to content

fix: use viewportY offset in Buffer() to read visible viewport#704

Open
gluonfield wants to merge 1 commit intocharmbracelet:mainfrom
gluonfield:fix/wait-screen-scroll-offset
Open

fix: use viewportY offset in Buffer() to read visible viewport#704
gluonfield wants to merge 1 commit intocharmbracelet:mainfrom
gluonfield:fix/wait-screen-scroll-offset

Conversation

@gluonfield
Copy link

Summary

Buffer() reads lines starting from index 0 of the scrollback buffer instead of the visible viewport. This causes Wait+Screen (and SaveOutput) to match against lines that have already scrolled off-screen.

The fix adds viewportY as the starting offset, consistent with how CurrentLine() already works in the same file.

Changes

One-line change in testing.go:

-buf, err := v.Page.Eval("() => Array(term.rows).fill(0).map((e, i) => term.buffer.active.getLine(i).translateToString().trimEnd())")
+buf, err := v.Page.Eval("() => { const s = term.buffer.active.viewportY; return Array(term.rows).fill(0).map((e, i) => term.buffer.active.getLine(s + i).translateToString().trimEnd()); }")

Reproduction

This tape fails on the current main but passes with this fix:

Output "/tmp/test.gif"
Set Height 300
Type "seq 10"
Enter
Sleep 1s
Wait+Screen /9/
Type "echo foo"
Enter
Sleep 1s

Stock VHS reports: timeout waiting for "Screen 9" to match 9; last value was: > seq 10 1 2 3 4 5 — it's reading from the top of the scrollback instead of the visible viewport.

Test plan

  • go test ./... passes
  • Reproduction tape passes with patched binary
  • Verified CurrentLine() already uses viewportY (consistent approach)

Fixes #659

Buffer() was reading lines from the top of the scrollback buffer
(index 0..N) instead of the visible viewport. This caused
Wait+Screen to fail after the terminal scrolled, since it matched
against lines no longer visible on screen.

The fix adds viewportY as the starting offset, consistent with how
CurrentLine() already works in the same file.

Fixes charmbracelet#659
@gluonfield gluonfield requested a review from a team as a code owner February 15, 2026 23:24
@gluonfield gluonfield requested review from aymanbagabas and meowgorithm and removed request for a team February 15, 2026 23:24
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.

Wait+Screen regex fails to match text in the viewport after scrolling

1 participant