Wrap last column to terminal width in CLI table formatter#11931
Wrap last column to terminal width in CLI table formatter#11931zachcasper wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the CLI table formatter to wrap long last-column values to the terminal width, improving readability for tables with long descriptions while preserving unwrapped output when terminal width is unknown.
Changes:
- Replaced
text/tabwriterusage with a custom table renderer. - Added last-column word wrapping, continuation-line padding, and related tests.
- Promoted
golang.org/x/termto a direct dependency.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
pkg/cli/output/table.go |
Implements terminal-width detection, custom column sizing, padding, and wrapping helpers. |
pkg/cli/output/table_test.go |
Adds tests for wrapping behavior, unknown-width output, long words, Unicode, and whitespace preservation. |
go.mod |
Marks golang.org/x/term as a direct dependency. |
Address Copilot review feedback on radius-project#11931: replace utf8.RuneCountInString with runewidth.StringWidth so that wide characters (CJK, emoji) and zero-width combining marks are accounted for correctly in column alignment and last-column wrapping. Long unbreakable words are now split at display-column boundaries rather than rune-count boundaries. - pkg/cli/output/table.go: switch padRight and wordWrap (and the slot/width computation) to use runewidth.StringWidth and runewidth.RuneWidth. - pkg/cli/output/table_test.go: add Test_Table_WrapsWideCharactersByDisplayWidth exercising CJK, and update the Unicode wrap expectation to reflect that 🚀 is two display columns wide. - go.mod: promote github.com/mattn/go-runewidth to a direct dependency.
Signed-off-by: Zach Casper <zachcasper@microsoft.com>
Address Copilot review feedback on radius-project#11931: replace utf8.RuneCountInString with runewidth.StringWidth so that wide characters (CJK, emoji) and zero-width combining marks are accounted for correctly in column alignment and last-column wrapping. Long unbreakable words are now split at display-column boundaries rather than rune-count boundaries. - pkg/cli/output/table.go: switch padRight and wordWrap (and the slot/width computation) to use runewidth.StringWidth and runewidth.RuneWidth. - pkg/cli/output/table_test.go: add Test_Table_WrapsWideCharactersByDisplayWidth exercising CJK, and update the Unicode wrap expectation to reflect that 🚀 is two display columns wide. - go.mod: promote github.com/mattn/go-runewidth to a direct dependency. Signed-off-by: Zach Casper <zachcasper@microsoft.com>
Fixes golangci-lint ineffassign: currentWidth is reassigned a few lines later from the long-word chunking loop, so the intermediate reset to 0 was dead. Signed-off-by: Zach Casper <zachcasper@microsoft.com>
Radius functional test overviewClick here to see the test run details
Test Status❌ Container images build failed |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11931 +/- ##
==========================================
+ Coverage 51.72% 51.81% +0.09%
==========================================
Files 726 726
Lines 45608 45711 +103
==========================================
+ Hits 23591 23686 +95
- Misses 19793 19800 +7
- Partials 2224 2225 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Fixes the misaligned/ugly CLI table output when a cell in the last column (typically
DESCRIPTION) is longer than the terminal width. The previoustext/tabwriter-based renderer let long lines overflow and wrap at the terminal boundary, breaking column alignment on continuation lines.This PR replaces the table renderer with a custom implementation that:
golang.org/x/term.Example
Before:
After:
Type of change
Fixes: #9756
Contributor checklist
Please verify that the PR meets the following requirements, where applicable:
eng/design-notes/in this repository, if new APIs are being introduced.