fix: keep help overlay within the terminal (two columns + height guard) #18

Merged
fiatcode merged 1 commit from fix/help-overlay-layout into main 2026-06-17 18:14:03 +07:00
Owner

Problem

The ? help overlay rendered as a single ~50-line column, and centerOverlay placed it with lipgloss.Place, which positions but never truncates. So on any terminal shorter than the panel (i.e. essentially all of them at 80×24), the top and bottom — including the ? or esc to close hint — were silently clipped off-screen. Help only ever knew the terminal width, never its height, so it couldn't defend against this.

Fix

  • Two-column layout. Key groups are split into two balanced columns (by line count) when the width allows it, roughly halving the panel height (~50 → ~27 lines). Falls back to a single width-clamped column when the terminal is too narrow for two.
  • Height-aware Help. NewHelp/SetSize now take height; the open site passes a.height.
  • Height guard. When height is known and the panel would overflow, body lines past the cap are dropped and replaced with a faint … resize terminal to see all keys indicator — while the title and close hint are always kept on screen. No more silent clipping.

Tests

  • New TestHelpHeightGuardClipsToTerminal asserts the rendered panel never exceeds the terminal height, the close hint survives, and the resize indicator appears.
  • Existing width/version tests updated for the 3-arg NewHelp.
  • Golden regenerated at a width wide enough to capture the two-column layout (verified: all 28 lines uniform width, border consistent).

go vet ./... && go test ./... green (7 packages).

Note on overlap with #17 (git sync)

This branches from main and is independent of the sync feature. Both touch internal/views/help.go (this PR rewrites the render path and renames helpSectionshelpGroups; #17 adds a Sync key row) and TestHelpGolden.golden. Whichever merges second will need a small rebase: re-add the Sync group to helpGroups and regenerate the golden.

## Problem The `?` help overlay rendered as a single ~50-line column, and `centerOverlay` placed it with `lipgloss.Place`, which positions but never truncates. So on any terminal shorter than the panel (i.e. essentially all of them at 80×24), the top and bottom — **including the `? or esc to close` hint** — were silently clipped off-screen. `Help` only ever knew the terminal *width*, never its *height*, so it couldn't defend against this. ## Fix - **Two-column layout.** Key groups are split into two balanced columns (by line count) when the width allows it, roughly halving the panel height (~50 → ~27 lines). Falls back to a single width-clamped column when the terminal is too narrow for two. - **Height-aware `Help`.** `NewHelp`/`SetSize` now take height; the open site passes `a.height`. - **Height guard.** When height is known and the panel would overflow, body lines past the cap are dropped and replaced with a faint `… resize terminal to see all keys` indicator — while the title and close hint are always kept on screen. No more silent clipping. ## Tests - New `TestHelpHeightGuardClipsToTerminal` asserts the rendered panel never exceeds the terminal height, the close hint survives, and the resize indicator appears. - Existing width/version tests updated for the 3-arg `NewHelp`. - Golden regenerated at a width wide enough to capture the two-column layout (verified: all 28 lines uniform width, border consistent). `go vet ./... && go test ./...` green (7 packages). ## Note on overlap with #17 (git sync) This branches from `main` and is independent of the sync feature. Both touch `internal/views/help.go` (this PR rewrites the render path and renames `helpSections`→`helpGroups`; #17 adds a `Sync` key row) and `TestHelpGolden.golden`. Whichever merges second will need a small rebase: re-add the `Sync` group to `helpGroups` and regenerate the golden.
fix: keep help overlay within the terminal (two columns + height guard)
All checks were successful
CI / vet-and-test (pull_request) Successful in 24s
a0d5f290f0
The help overlay rendered as one ~50-line column and centerOverlay placed
it with lipgloss.Place, which never truncates — so on any terminal shorter
than the panel the top and bottom (including the close hint) were silently
clipped. Help only knew the terminal width, never its height.

- Lay the key groups out in two balanced columns when the width allows it
  (single column, width-clamped, when it doesn't), roughly halving height.
- Make Help height-aware (NewHelp/SetSize now take height) and add a height
  guard: body lines past the cap are dropped with a faint 'resize' hint,
  while the title and close hint always stay on screen.
- Cover the height guard with a test; golden now renders the two-column
  layout at a width wide enough to show it.
fiatcode force-pushed fix/help-overlay-layout from a0d5f290f0
All checks were successful
CI / vet-and-test (pull_request) Successful in 24s
to 5afb3ef239
All checks were successful
CI / vet-and-test (pull_request) Successful in 24s
2026-06-17 18:13:04 +07:00
Compare
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
fiatcode/weft!18
No description provided.