Skip to content

fix(help): align columns + surface sort and screen-switch keys#4

Merged
torosent merged 1 commit into
mainfrom
fix/help-alignment-and-coverage
May 4, 2026
Merged

fix(help): align columns + surface sort and screen-switch keys#4
torosent merged 1 commit into
mainfrom
fix/help-alignment-and-coverage

Conversation

@torosent
Copy link
Copy Markdown
Owner

@torosent torosent commented May 4, 2026

Re-opened from #3 (auto-closed when base branch was deleted on PR #2 merge).

Two issues from the user's screenshot

Misalignment

The 2-column help layout used %-40s %s to pad the combined "label + keys" string. Since keys vary in length ([s] vs [shift+p, P] is 9 chars apart), every right-side cell ended at a different column.

Rewrote to padRight(label, maxLabel) + " " + padRight(keys, maxKeys) with a fixed column separator. Every right-side [ now sits at the same column.

Two undocumented bindings

Shift+S (sort picker) and 1-9, 0 (k9s-style screen quick-switch) were both wired up in app.go but never added to keymap.Default(). Added both as catalog-only entries so they show up in ?.

Tests

  • TestHelpModel_TwoColumnAlignment regression guard
  • TestHelpModel_IncludesSortAndScreenSwitch
  • All existing tests still pass
  • make ci clean: total coverage 70.3%

## Alignment

The previous help layout used '%-40s  %s' to pad the combined "label +
keys" string for each two-column row. Since key strings vary in length
(e.g. "[s]" = 3 chars vs "[shift+p, P]" = 12), the padding eaten by
the keys segment shifted the right column by 9 characters between rows
— visible misalignment in the user's screenshot.

Rewrote the layout to:
  1. Compute max label width and max keys width across all bindings,
  2. Render each cell as `padRight(label, maxLabel) + " " + padRight(keys, maxKeys)`,
  3. Join left + colSep + right cell per row, falling back to one
     column when the terminal is too narrow.

All right-side `[` characters now sit at a stable column.

## Coverage of bindings

Two working bindings were never registered in keymap.Default(), so they
silently never appeared in the help overlay:
  * Shift+S  — opens the column sort picker (handled in app.go's Update,
                bypasses keymap.Matches)
  * 1-9, 0   — k9s-style screen quick-switch (handled by numberShortcut
                in app.go)

Added both to keymap.Default() with informational keys arrays
("shift+s, S" and "1-9, 0") and short Help labels ("sort" and
"switch screen"). The functional dispatch is unchanged — these
entries are catalog-only so the help renders them.

## Tests

- TestHelpModel_TwoColumnAlignment is a regression test that strips
  ANSI from the rendered help and asserts every right-side "[" sits at
  the same column across all body rows.
- TestHelpModel_IncludesSortAndScreenSwitch asserts the new entries
  appear with their key labels.
- Existing TestHelpListsAllBindings continues to pass.

Verified locally with make ci: gofumpt clean, go vet clean,
staticcheck clean, golangci-lint clean, race tests pass, total
coverage 70.3% (above 70% gate).
@torosent torosent force-pushed the fix/help-alignment-and-coverage branch from 7f9cc30 to 4a1b576 Compare May 4, 2026 17:05
@torosent torosent merged commit 5a8a3e5 into main May 4, 2026
2 checks passed
@torosent torosent deleted the fix/help-alignment-and-coverage branch May 4, 2026 17:07
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