Skip to content

cmdio: add Width, PadRight, and PadLeft helpers for column alignment#5394

Open
pietern wants to merge 1 commit into
mainfrom
cmdio-visible-width
Open

cmdio: add Width, PadRight, and PadLeft helpers for column alignment#5394
pietern wants to merge 1 commit into
mainfrom
cmdio-visible-width

Conversation

@pietern
Copy link
Copy Markdown
Contributor

@pietern pietern commented Jun 1, 2026

Adds Width, PadRight, and PadLeft to libs/cmdio for aligning columns of colored text. Width returns the visible terminal-cell width, ignoring ANSI color escapes and counting wide glyphs (CJK, emoji, fullwidth Latin) as two cells; the Pad* helpers pad to a visible width, measuring the rendered string so already-colored cells stay aligned.

This lets commands print color-per-cell tables without the "measure the uncolored string, pad by hand" dance that misaligns rows on any escape sequence or wide glyph — something text/tabwriter can't fix, since it counts runes. Implemented via lipgloss.Width, already a direct dependency.

This pull request and its description were written by Isaac.

Adds Width, PadRight, and PadLeft to libs/cmdio for aligning columns of
colored text. Width returns the visible terminal-cell width, ignoring ANSI
color escapes and counting wide glyphs (CJK, emoji, fullwidth Latin) as two
cells; the Pad* helpers pad to a visible width, measuring the rendered string
so already-colored cells stay aligned.

This lets commands print color-per-cell tables without the "measure the
uncolored string, pad by hand" dance that misaligns rows on any escape sequence
or wide glyph -- something text/tabwriter can't fix, since it counts runes.
Implemented via lipgloss.Width, already a direct dependency.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

Waiting for approval

Could not determine reviewers from git history.
Round-robin suggestion: @Divyansh-db

Eligible reviewers: @Divyansh-db, @chrisst, @hectorcast-db, @mihaimitrea-db, @parthban-db, @rauchy, @renaudhartert-db, @simonfaltum, @tanmay-db, @tejaskochar-db

Suggestions based on git history. See OWNERS for ownership rules.

@pietern pietern temporarily deployed to test-trigger-is June 1, 2026 12:28 — with GitHub Actions Inactive
@pietern pietern temporarily deployed to test-trigger-is June 1, 2026 12:28 — with GitHub Actions Inactive
@pietern
Copy link
Copy Markdown
Contributor Author

pietern commented Jun 1, 2026

@akshaysingla-db @simonfaltum This avoids the additional direct dep in #5223.

@pietern pietern enabled auto-merge June 1, 2026 12:29
@eng-dev-ecosystem-bot
Copy link
Copy Markdown
Collaborator

Commit: 4fc810f

Run: 26754910144

pietern added a commit that referenced this pull request Jun 1, 2026
Switch `lakebox list` and `ssh-key list` from mattn/go-runewidth to the
cmdio.Width / cmdio.PadRight helpers added in #5394. Because PadRight measures
the rendered (already-colored) string, this drops the manual "measure the
uncolored cell, color it, then pad by hand" dance that the old code needed to
keep ANSI escapes from throwing off alignment.

With the only direct runewidth importers gone, demote go-runewidth back to an
indirect dependency and drop its NOTICE entry; it remains in the module graph
transitively via charmbracelet/x/ansi (which is what cmdio.Width calls through).

Co-authored-by: Isaac
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.

2 participants