Skip to content

fix(tui): guard render paths against tiny terminals#149

Merged
yishuiliunian merged 1 commit into
mainfrom
fix/tui-tiny-terminal-panic
May 13, 2026
Merged

fix(tui): guard render paths against tiny terminals#149
yishuiliunian merged 1 commit into
mainfrom
fix/tui-tiny-terminal-panic

Conversation

@yishuiliunian
Copy link
Copy Markdown
Contributor

Summary

  • iPad mosh terminals (~14 rows) crashed loopal at boot: compute_overlay_height called u16::clamp(8, max_h / 2) and panicked on min > max. Same shape in compute_overlay_width for max_w < 40.
  • Hardened the TUI render path so no view panics on extreme terminal sizes, plus added regression coverage.

Changes

  • crates/loopal-tui/src/views/topology_overlay/layout.rs — introduce safe_clamp that collapses inverted (lower, upper) pairs before delegating to u16::clamp; rewrite compute_overlay_width / compute_overlay_height to use it.
  • crates/loopal-tui/src/views/topology_overlay/mod.rs — minimum-area guard (area.width < 40 || area.height < 16) at render_topology_overlay entry; small terminals skip the overlay rather than fight for space.
  • crates/loopal-tui/src/views/picker.rsrender_thinking_indicator uses saturating_sub, removing the implicit reliance on the upstream area.width < 30 early-return guard.
  • Regression tests cover max_w/max_h ∈ {0, 1, 7, 14, 15, 16, 39, 40, ...} plus safe_clamp inverted-bounds cases.

Test plan

  • bazel test //crates/loopal-tui:loopal-tui_test (local — passes)
  • bazel build //crates/loopal-tui:loopal-tui --config=clippy (local — clean)
  • CI passes

iPad mosh terminals (height ~14 rows) crashed loopal because
`compute_overlay_height` called `u16::clamp(8, max_h / 2)` and panicked
on `min > max` when `max_h < 16`. The same shape also exists in
`compute_overlay_width` for `max_w < 40`.

- Introduce `safe_clamp` that collapses an inverted (lower, upper)
  pair before delegating to `u16::clamp`.
- Add a minimum-area guard at `render_topology_overlay` entry so the
  overlay is skipped (instead of fighting for space) on small screens.
- Switch `picker::render_thinking_indicator` to `saturating_sub` so
  the raw u16 arithmetic no longer depends on the upstream
  `area.width < 30` early return.
- Cover the panic surface with edge-value regression tests.
@yishuiliunian yishuiliunian merged commit 03e976c into main May 13, 2026
4 checks passed
@yishuiliunian yishuiliunian deleted the fix/tui-tiny-terminal-panic branch May 13, 2026 17:10
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