Skip to content

fix(tui): stop narrow table panes from underflowing the column width - #587

Merged
LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/percentage-width-underflow
Sep 26, 2026
Merged

LargeModGames merged 1 commit into
LargeModGames:mainfrom
kapok-4o:fix/percentage-width-underflow

Conversation

@kapok-4o

@kapok-4o kapok-4o commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #540. get_percentage_width subtracted its 3-column padding with a plain -, so a table pane narrower than 3 columns panicked in debug builds and wrapped in release builds. It now uses saturating_sub.

Also adds tests for get_percentage_width and truncate_text, following the cases in the issue:

  • widths 0 to 3 give 0, and (103, 0.5) gives 50
  • short text is kept as is
  • truncate_text("abcdef", 4) gives "abc…" with a single … char
  • "héllo wörld" with max 5 is checked with .chars().count()

test_attribute_total goes from 2286 to 2291 for the five new tests.

Testing

  • cargo fmt --all -- --check: clean
  • cargo clippy --no-default-features --features telemetry,tui -- -D warnings: clean
  • cargo test --no-default-features --features telemetry,tui: 1262 passed, 0 failed
  • With the fix reverted, percentage_width_is_zero_when_the_pane_is_no_wider_than_the_padding fails with attempt to subtract with overflow, so the test catches the bug.

Additional notes

This is the first of the small PRs mentioned in #586. I wrote it with an AI coding assistant and reviewed the change myself.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Fixed track-table columns collapsing incorrectly when the available pane is narrower than three columns. Columns now shrink to zero width rather than underflowing or wrapping, improving display in very narrow layouts.

get_percentage_width subtracted its 3-column padding with a plain `-`,
so a pane narrower than 3 columns panicked in debug builds and wrapped
in release builds. Use saturating_sub, and cover get_percentage_width
and truncate_text with tests.

Fixes LargeModGames#540

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: LargeModGames/spotatui/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: d0af8569-c9ae-4459-8feb-b222777b09e3

📥 Commits

Reviewing files that changed from the base of the PR and between 6abfae1 and 801303b.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • src/tui/ui/util.rs
  • tools/gates.count

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

get_percentage_width now returns zero when the pane width is at most three. Tests cover width boundaries, percentage calculation, and truncate_text. The changelog and test-attribute baseline are updated.

Changes

Narrow pane width handling

Layer / File(s) Summary
Width calculation and validation
src/tui/ui/util.rs, CHANGELOG.md, tools/gates.count
get_percentage_width uses saturating subtraction for the three-column padding. Tests cover widths zero through three, percentage calculation, and text truncation. The changelog records the fix, and the test-attribute baseline increases from 2286 to 2291.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 80130

Narrow table panes now receive zero width for percentage-based columns when they cannot fit the padding, avoiding the previous underflow. The supplied changes identify no remaining merge-blocking risk.

Architecture Summary

Architecture risk: 🔵 Low · up to 80130

The change affects 3 systems.

Changed systems: src, CHANGELOG.md, tools

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — src (ui) was modified; 1 changed file maps to changed impact.
  • observed — CHANGELOG.md (service) was modified; 1 changed file maps to changed impact.
  • observed — tools (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in CHANGELOG.md: The Unreleased changelog adds a Fixed entry describing the narrow-table crash and its reported resolution: columns shrink to zero width when the table is under three columns wide.
  • observed — Modified behavior in src/tui/ui/util.rs: get_percentage_width now saturates the subtraction of 3 padding columns, so widths below 3 produce zero rather than underflowing.
  • observed — Modified behavior in src/tui/ui/util.rs: Added tests covering zero output for pane widths 0–3, applying 50% to the width remaining after padding, preserving text that fits, appending one ellipsis when truncating, and counting Unicode characters rather than bytes.
  • observed — Modified behavior in tools/gates.count: The test_attribute_total baseline changes from 2286 to 2291.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the allowed fix(tui): prefix, clearly describes the narrow-pane underflow fix, and uses a concise imperative subject.
Linked Issues check ✅ Passed The PR satisfies the coding requirements in [#540]. get_percentage_width uses saturating_sub(3), so widths 0 through 3 return zero without underflow. Tests cover the required (103, 0.5) result, …
Out of Scope Changes check ✅ Passed The changed files stay within [#540]. The utility fix and its tests implement the issue. The gate count update supports the added tests. The changelog entry documents the same narrow-pane fix. No unre…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
✨ Simplify code
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@LargeModGames
LargeModGames merged commit 0ed4a07 into LargeModGames:main Sep 26, 2026
31 checks passed
@LargeModGames

Copy link
Copy Markdown
Owner

@all-contributors please add @2570165831 for code

@allcontributors

Copy link
Copy Markdown
Contributor

@LargeModGames

I've put up a pull request to add @2570165831! 🎉

LargeModGames pushed a commit that referenced this pull request Sep 26, 2026
Adds @2570165831 as a contributor for code.

This was requested by LargeModGames [in this
comment](#587 (comment))

[skip ci]

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
LargeModGames pushed a commit that referenced this pull request Sep 26, 2026
# Summary

Fixes #553. The SHIFT arm of `impl From<event::KeyEvent> for Key` only
uppercased ASCII letters. It now uppercases any lowercase letter whose
uppercase is a single char, so Shift+`ö` gives `Ö` and Shift+`é` gives
`É`. `ß` (uppercase `SS`) stays `ß`.

Adds the first tests for `key.rs`, with the cases from the issue:

- `ö` + SHIFT gives `Ö`, `é` + SHIFT gives `É`
- `ß` + SHIFT stays `ß`
- `p` + SHIFT still gives `P`
- `Ö` + SHIFT stays `Ö`

`test_attribute_total` goes from 2291 to 2295. Rebased on top of #587,
which touched the same two lines in `tools/gates.count` and the
`[Unreleased]` changelog.

# Testing

- `cargo fmt --all -- --check`: clean
- `cargo clippy --no-default-features --features telemetry,tui -- -D
warnings`: clean
- `cargo test --no-default-features --features telemetry,tui`: 1266
passed, 0 failed (after the rebase)
- `cargo test --no-default-features --features telemetry,tui
shift_with_a_lowercase`: 1 passed
- With the old ASCII-only guard put back,
`shift_with_a_lowercase_non_ascii_letter_gives_its_uppercase_char` fails
and the other three pass.

# Additional notes

I tried to reproduce this on a real terminal: Ghostty 1.3.1 on macOS,
with the same keyboard enhancement flags spotatui pushes (the probe
reported the protocol as on). With a US (ABC) layout, in the English
input mode:

- Shift+P arrives as `Char('P')` with SHIFT, not `Char('p')` with SHIFT
- Option-composed É arrives as `Char('É')` with no modifier
- Option acts as Alt under the protocol, so Option+s arrives as `s` with
ALT rather than `ß`

So I couldn't hit the lowercase-plus-SHIFT case on Ghostty with a US
layout. It may still show up on other terminals (#141) or on layouts
with a physical ö key, which I don't have. The fix doesn't change
anything for the events above.

I wrote this with an AI coding assistant and reviewed the change myself.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: 2570165831 <[email protected]>
Co-authored-by: Claude Opus 5.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.

Narrow table panes panic in get_percentage_width (u16 underflow)

2 participants