Skip to content

Bug: Wait+Screen fails to match text after terminal scrolling #1

@lancy

Description

@lancy

Summary

The Wait+Screen command fails to match text that appears on screen after terminal scrolling. It searches the top of the scrollback buffer instead of the currently visible viewport.

Bug Details

Symptom

Type "vm0 cook start"
Enter
Wait+Screen@120s /Run completed successfully/
# Times out even though text is visible on screen

Error message:

timeout waiting for "Screen Run completed successfully" to match Run completed successfully; 
last value was: [shows old content from top of buffer, not current screen]

Root Cause

The VHS.Buffer() method in vhs.go does not account for scroll position. When terminal output causes scrolling, it continues reading from the top of the scrollback buffer instead of the visible viewport.

Upstream References

Resource URL
Bug Report charmbracelet#659
Proposed Fix charmbracelet#658
Related Issue charmbracelet#657

Key Files to Investigate

  1. vhs.go - Contains Buffer() method that needs fixing
  2. command.go - Wait command implementation, calls Buffer()

PR charmbracelet#658 Fix Approach

The PR title: "fix: capture visible viewport in VHS.Buffer"

The fix should modify Buffer() to:

  1. Get current scroll position
  2. Calculate visible viewport based on terminal rows
  3. Return content from visible area, not scrollback top

Test Case

Create test.tape:

Output test.gif
Set Shell bash
Set FontSize 16
Set Width 800
Set Height 600

# Generate scrolling output
Type "for i in {1..50}; do echo Line $i; done"
Enter
Sleep 2s

# This should match "Line 50" visible on screen
Wait+Screen@10s /Line 50/

Type "echo done"
Enter
Sleep 1s

Expected: Should find "Line 50" on visible screen
Actual: Times out because it searches top of buffer (Line 1, 2, 3...)

Success Criteria

  1. Wait+Screen matches text visible after scrolling
  2. Existing tests pass
  3. No regression in Wait without +Screen modifier

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions