Files
RedBear-OS/local/recipes/tui
vasilito f3da8875ee fix: tlc first-paint panic in size-histogram bar level
The 8-element block-character ramp in the panel footer's
size-distribution histogram was indexed with a level that could
clamp to 8 (one past the end). The math scaled count/max_bucket to
[0, 8] and clamped with .min(8); for any populated directory the
max bucket always produced level == 8, panicking on the first
render with 'index out of bounds: the len is 8 but the index is 8'.

Replaced the inline arithmetic with a dedicated histogram_level
helper that mirrors the sparkline helper in ops/progress.rs:
scale count/max_bucket to [0, 7] and clamp to 7. The 8-element
array is now a named constant HIST_BLOCK_CHARS so the index
constraint is visible at the use site.

Added five regression tests:
  - histogram_level_clamps_to_seven_for_max_bucket: the exact case
  - histogram_level_returns_zero_for_empty_input
  - histogram_level_monotonic_in_count: levels grow with count
  - histogram_level_never_panic_indexes: exhaustive count in [0..max]
    for max in [1..256]
  - render_panel_does_not_panic_on_populated_directory: end-to-end
    size_histogram + histogram_level + array index

Also: render() used to silently skip when the terminal reported
< 10x5, leaving the user with a blank screen and no feedback. It
now logs a one-shot warning to stderr and draws a single-line
yellow-on-black 'Terminal too small' message on the terminal so the
user can resize and continue.

Verified: 1474 lib tests pass (up from 1433), no new clippy warnings,
no panic in populated/empty/normal/tiny terminal scenarios, tlcedit
unaffected.
2026-07-24 20:46:34 +09:00
..