Skip to content

fix(ui): prevent error and modal overflow - #48

Merged
sebasv merged 2 commits into
mainfrom
prevent-overflow
May 4, 2026
Merged

fix(ui): prevent error and modal overflow#48
sebasv merged 2 commits into
mainfrom
prevent-overflow

Conversation

@sebasv

@sebasv sebasv commented May 4, 2026

Copy link
Copy Markdown
Owner

Summary

Long errors were silently clipped to the modal's single-line slot, hiding the actionable tail (e.g. No such file or directory (os error 2) rendered as just No such file). Modals also assumed a generously sized terminal and broke their layout when shrunk. This PR introduces shared wrap/truncate helpers and applies them across every modal that surfaces an error or a user-supplied path/branch/repo name.

Changes

  • Wrap & ellipsize errors. New wrap_message(msg, width, max_lines) in ui/mod.rs honors embedded \n (anyhow's {:#} formatting), word-wraps, hard-breaks paths longer than the line, and ellipsizes the last shown line when content gets dropped (cap: 3 lines). Used by add_repo (both variants), confirm::render_remove_worktree, and discovered. Modal heights grow to match wrapped error length so we never push the slot past the border.
  • Continuation indent. Wrapped error continuations use a 4-col indent so they line up under the first character of the message rather than under the ! prefix.
  • Truncate long titles & body strings. Modal titles, the Worktree: line, and the unmerged-branch warning all run truncate_to_width against the available budget. Long branch names can no longer eat the closing border corner.
  • Min-size guard. Below 50×12, ui::render paints a yellow Terminal too small (need at least 50×12) placeholder instead of letting the sidebar+main+modal layout collapse.
  • Shared truncate helper. Promoted sidebar's private truncate to pub fn truncate_to_width in ui/mod.rs; sidebar reuses it.

Test plan

  • cargo test — 153 passed (12 new: wrap helpers + tiny-terminal guard + long-error wrap snapshot for AddRepo).
  • cargo clippy --all-targets -- -D warnings clean.
  • cargo fmt --all -- --check clean.
  • Updated snapshots for AddRepo modal show the full ... No such file or directory (os error 2) wrapped onto two lines, with the modal height growing by one row.
  • Manual smoke: trigger an Add Repo failure with a very long path, resize terminal below 50×12, verify graceful placeholder and recovery on resize.

🤖 Generated with Claude Code

sebasv and others added 2 commits May 4, 2026 13:59
Long errors used to be silently clipped to the modal's single-line slot,
hiding the actionable tail (e.g. "No such file or directory (os error 2)"
became "No such file"). Modals also assumed a generously sized terminal
and broke their layout when shrunk.

- Add `wrap_message` (cap at 3 lines, ellipsize) and `truncate_to_width`
  helpers in `ui/mod.rs`. Errors in add-repo, new-worktree, remove-worktree,
  and discovered-repos modals now wrap up to 3 lines with a "    "
  continuation indent and grow the modal height to match.
- Truncate long branch / repo / path strings in modal titles and the
  "Worktree:" / unmerged-branch warning lines so they can't eat borders.
- Render a "Terminal too small" placeholder below 50x12 instead of letting
  the sidebar+main+modal layout collapse.
- Promote sidebar's private `truncate` to the shared `truncate_to_width`.

Co-Authored-By: Claude <noreply@anthropic.com>
@sebasv
sebasv merged commit b13b6fe into main May 4, 2026
1 check passed
@sebasv
sebasv deleted the prevent-overflow branch May 4, 2026 12:06
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