fix(tui): guard render paths against tiny terminals#149
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
compute_overlay_heightcalledu16::clamp(8, max_h / 2)and panicked onmin > max. Same shape incompute_overlay_widthformax_w < 40.Changes
crates/loopal-tui/src/views/topology_overlay/layout.rs— introducesafe_clampthat collapses inverted (lower, upper) pairs before delegating tou16::clamp; rewritecompute_overlay_width/compute_overlay_heightto use it.crates/loopal-tui/src/views/topology_overlay/mod.rs— minimum-area guard (area.width < 40 || area.height < 16) atrender_topology_overlayentry; small terminals skip the overlay rather than fight for space.crates/loopal-tui/src/views/picker.rs—render_thinking_indicatorusessaturating_sub, removing the implicit reliance on the upstreamarea.width < 30early-return guard.max_w/max_h ∈ {0, 1, 7, 14, 15, 16, 39, 40, ...}plussafe_clampinverted-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)