Skip to content

Conversation

@semihbkgr
Copy link

Summary

  • Add guard in visibleLines() to prevent slice bounds panic when top >= bottom
  • Add tests for negative and zero height scenarios

Details

When viewport height becomes negative (e.g., during terminal resize with other components), visibleLines() panics with
"slice bounds out of range [N:M]" where N > M.

This happens because:

  1. h = Height - Style.GetVerticalFrameSize() becomes negative
  2. bottom = clamp(YOffset + h, top, len(lines)) becomes less than top
  3. lines[top:bottom] panics

Fixes #879

When viewport height becomes negative (e.g., during terminal resize),
visibleLines() could panic with "slice bounds out of range" because
bottom becomes less than top in the slice operation.

Add a guard to return nil when top >= bottom to prevent the panic.

Fixes charmbracelet#879

Co-Authored-By: Claude Opus 4.5 <[email protected]>
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.

viewport: panic with slice bounds out of range when height is negative or zero

1 participant