cmdio: add Width, PadRight, and PadLeft helpers for column alignment#5394
Open
pietern wants to merge 1 commit into
Open
cmdio: add Width, PadRight, and PadLeft helpers for column alignment#5394pietern wants to merge 1 commit into
pietern wants to merge 1 commit into
Conversation
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
Contributor
Waiting for approvalCould not determine reviewers from git history. Eligible reviewers: Suggestions based on git history. See OWNERS for ownership rules. |
Contributor
Author
|
@akshaysingla-db @simonfaltum This avoids the additional direct dep in #5223. |
Collaborator
|
Commit: 4fc810f |
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
Width,PadRight, andPadLefttolibs/cmdiofor aligning columns of colored text.Widthreturns the visible terminal-cell width, ignoring ANSI color escapes and counting wide glyphs (CJK, emoji, fullwidth Latin) as two cells; thePad*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/tabwritercan't fix, since it counts runes. Implemented vialipgloss.Width, already a direct dependency.This pull request and its description were written by Isaac.