Skip to content

fix: reclaim wasted rows below the shortcut footer - #55

Merged
wu-json merged 3 commits into
mainfrom
fix/fix-shortcuts-bottom-spacing
Apr 27, 2026
Merged

wu-json merged 3 commits into
mainfrom
fix/fix-shortcuts-bottom-spacing

Conversation

@wu-json

@wu-json wu-json commented Apr 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Eliminate ~3 wasted rows between the shortcut footer and the bottom of the terminal in both the main page and the log view, and add regression tests.

Commentary

There were three separate height-accounting bugs causing the bottom of the terminal to look empty:

  1. MainPage.tsx: headerHeight was hardcoded to 4, but the View header only renders 2 rows (Curse v{version} and Config: {filename}). This wasted 2 rows.
  2. MainPage.tsx: Math.max(4, availableForLogs - 1) had an extra - 1 safety buffer that wasted another row.
  3. ShortcutFooter: getShortcutFooterHeight() returned 0 when shortcuts were hidden, but the component still renders the ? for shortcuts text (1 row).
  4. LogPage.tsx: The fixed-row offset was 6 but the actual overhead is 3 (View header 2 + LogPage title 1), and the sign on the collapsed-footer adjustment was inverted.

After the fix, the math adds up to exactly terminalHeight in both views:

  • MainPage: 2 (header) + (N+3) (table) + logPreview + 1 (footer) = T
  • LogPage: 2 (header) + 1 (title) + logTable + 1 (footer) = T

To prevent regressions and improve testability, the layout math has been extracted into a new pure module at src/ui/layout.ts:

  • getShortcutFooterColumns / getShortcutFooterHeight
  • computeMainPageLayout
  • computeLogPageLayout

getShortcutFooterHeight now returns 1 (instead of 0) when shortcuts are hidden, which removes the need for +1 / -1 fixups at every call site. MainPage, LogPage, ShortcutFooter, and View all import from the new module so the constants stay in sync.

Tests

src/ui/layout.test.ts adds 18 new tests covering:

  • Column thresholds for the footer at each terminal-width breakpoint
  • Footer returns 1 row when collapsed (direct regression for the bug)
  • Sum invariant: MainPage and LogPage heights sum to exactly terminalHeight in collapsed, expanded, and search modes — this is the core invariant that was broken
  • Min log preview height clamping in tight terminals
  • Expanding shortcuts shrinks the log area by exactly the footer delta
  • Search mode reduces the log table by exactly one row

wu-json added 2 commits April 26, 2026 17:17
The ShortcutFooter always renders at least 1 row (the "? for shortcuts" text), but getShortcutFooterHeight returns 0 when shortcuts are hidden. This left 1 unaccounted row creating a gap at the bottom of the terminal. Fix by adding +1 to the footer height calculation when showShortcuts is false, in both the main page and logs page height calculations.
…m rows

The previous fix only addressed 1 of 3 wasted rows. Two additional issues:

1. headerHeight was 4 in MainPage, but the View header only renders 2 rows
   (Curse v{version} and Config: {filename}). This wasted 2 rows.

2. Math.max(4, availableForLogs - 1) added an extra unused row as a buffer.
   Removed since the math now adds up exactly to terminalHeight.

3. LogPage used 6 as the fixed-row offset, but the actual fixed overhead
   is 3 (View header 2 + LogPage title 1). Also fixed sign on the
   showShortcuts adjustment - hidden footer takes 1 row, so LogTable
   should be smaller by 1, not larger.

Updated normalMinHeight in View.tsx to match.
@wu-json wu-json changed the title fix: reduce wasted space when shortcuts are collapsed or shown fix: reclaim wasted rows below the shortcut footer Apr 27, 2026
The TUI height calculations were previously inline in MainPage.tsx and
LogPage.tsx and mixed with ink hooks, making them hard to unit test. This
extracts the math into src/ui/layout.ts as pure functions:

- getShortcutFooterColumns / getShortcutFooterHeight
- computeMainPageLayout
- computeLogPageLayout

getShortcutFooterHeight now returns 1 (instead of 0) when shortcuts are
hidden, accurately reflecting the rendered "? for shortcuts" row. This
removes the need for the +1 / -1 adjustments at every call site.

Adds src/ui/layout.test.ts covering:
- Column thresholds for the footer
- Footer returns 1 row when collapsed (regression)
- MainPage and LogPage heights summing to exactly terminalHeight in
  collapsed, expanded, and search modes (the core invariant that broke)
- Min log preview height clamping in tight terminals
- Expanding shortcuts shrinks the log area by the footer delta
@wu-json
wu-json merged commit f8942d9 into main Apr 27, 2026
1 check passed
@wu-json
wu-json deleted the fix/fix-shortcuts-bottom-spacing branch April 27, 2026 00:29
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