Skip to content

fix(cli): align box borders in gain, cheatsheet and config show - #1094

Closed
andig wants to merge 1 commit into
yvgude:mainfrom
andig:fix/cli-box-alignment
Closed

fix(cli): align box borders in gain, cheatsheet and config show#1094
andig wants to merge 1 commit into
yvgude:mainfrom
andig:fix/cli-box-alignment

Conversation

@andig

@andig andig commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Several CLI dashboards draw framed boxes by padding rows with a hardcoded run of spaces. That only lines up for one specific input — as soon as the interpolated value changes length, or carries ANSI colour, the right border drifts. theme::pad_right / theme::visual_len already solve this correctly (ANSI-aware, wide-char-aware); these three sites just weren't using them.

Before

lean-ctx gain
  ╭──────────────────────────────────────────╮
  │ Your first week!                         │
  │ You saved 5.1M tokens this week.      │     <- drifts with the token count
  │ Share your card? lean-ctx gain --wrapped │
  ╰──────────────────────────────────────────╯

lean-ctx cheatsheet
╔══════════════════════════════════════════════════════════════╗
║  lean-ctx Workflow Cheat Sheet                     v3.9.12  ║   <- 1 col short, grows with version
╚══════════════════════════════════════════════════════════════╝

lean-ctx config show
╭─── Simplified (high-level) ───────────────────────────────╮     <- 59
│ compression_level   = Lite        ← config                       <- no right border
╰────────────────────────────────────────────────────────────╯    <- 60

After

All rows pad to a named interior width; every border lines up.

╭─── Simplified (high-level) ────────────────────────────────╮
│ compression_level   = Lite        ← config                 │
│ memory_profile      = Performance  ← default               │
╰────────────────────────────────────────────────────────────╯

Changes

  • core/stats/format/dashboard.rs — weekly-nudge card builds rows through a pad_right closure, matching the hero box right above it
  • cli/cheatsheet_cmd.rs — version right-aligned in a computed field instead of a literal space run (was also 1 column short of the frame)
  • cli/config_cmd.rsbox_top/box_bottom/box_row helpers; rows now actually close, and both frames share one SHOW_BOX_W

Verification

Swept 86 read-only subcommands with a script that strips ANSI, measures each box row in terminal columns (wide chars = 2, combining/VS = 0) and flags rows whose width differs from the rest of their box. 26 boxes rendered; 3 misaligned rows before, 0 after.

Static sweep of every source literal containing │ ┃ ║ plus every box_side() row builder found no further instances of the same bug shape.

Scope caveat: 78 of the 86 commands print no box in a fresh environment (no data / not provisioned), so those paths are covered by the static sweep only.

Added show_box_borders_line_up — asserts top, bottom and padded rows agree in visual width, including an overlong row that must truncate rather than overflow. cargo fmt/clippy clean (the one remaining clippy warning, a wildcard import in core/ocla/registry.rs, is pre-existing and untouched).

🤖 Generated with Claude Code

Three box renderers padded rows with hardcoded runs of spaces instead of
the width-aware theme::pad_right helper, so any variable-length or
ANSI-coloured content pushed the right border out of line.

- gain: weekly-nudge card rows drifted with the token count
- cheatsheet: header row was 1 column short and grew with the version
- config show: rows had no right border at all; top/bottom differed by
  1-3 columns between the two frames

All three now pad to a named interior width via theme::pad_right.

@yvgude yvgude left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: fix(cli): align box borders

Clean, well-structured fix.

What it does:

  • Extracts box_top(), box_bottom(), box_row() helpers with constant SHOW_BOX_W = 60
  • Fixes cheatsheet header: uses {ver_pad:>29} for version alignment instead of hardcoded spaces
  • Fixes config show: dynamic width via pad_right() ensures right border aligns regardless of value length
  • Fixes dashboard gain hero "first week" box: nudge_line() closure handles variable token counts

Quality:

  • show_box_borders_line_up test verifies visual alignment for multiple labels, short and overlong content
  • Uses existing theme::visual_len() and theme::pad_right() for ANSI-aware width calculation
  • No hardcoded column arithmetic that could drift

LGTM.

yvgude added a commit that referenced this pull request Jul 21, 2026
@yvgude

yvgude commented Jul 21, 2026

Copy link
Copy Markdown
Owner

Merged to main via CLI rebase+merge (part of batch merge session).

@yvgude yvgude closed this Jul 21, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants