Skip to content

Narrow table panes panic in get_percentage_width (u16 underflow) #540

Description

@LargeModGames

What

get_percentage_width subtracts a 3-column padding from a u16 with plain -, so a table pane narrower than 3 columns panics in debug builds (attempt to subtract with overflow) and silently wraps in release builds. I hit it by opening a track table and pressing } until the sidebar fills the screen. I'd also like tests for this function and its neighbor truncate_text, which has none.

Where to look

  • get_percentage_width, truncate_text and the mod tests at the bottom of src/tui/ui/util.rs

Possible solution

  • The fix is one call: width.saturating_sub(padding).
  • Write the failing test first: get_percentage_width(2, 0.5) panics under cargo test today.
  • Good cases: widths 0 to 3 give 0, (103, 0.5) gives 50, and truncate_text("abcdef", 4) gives "abc…" (one … char, not three dots). For "héllo wörld" with max 5, check .chars().count(), not .len().
  • Name tests as behavior sentences with no test_ prefix or _test suffix (the two existing tests predate that rule).
  • Each new #[test] raises test_attribute_total in tools/gates.count by one. If the number is off, cargo test fails in src/gates.rs and prints the right one.

Done when

  • New tests for both functions pass.
  • cargo fmt --all -- --check, cargo clippy --no-default-features --features telemetry,tui -- -D warnings and cargo test --no-default-features --features telemetry,tui pass.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions