Wrap last column to terminal width in CLI table formatter#11829
Wrap last column to terminal width in CLI table formatter#11829
Conversation
Agent-Logs-Url: https://github.com/radius-project/radius/sessions/0e0d575c-c4f7-4f21-9cae-42d9aa0dda88 Co-authored-by: zachcasper <30731731+zachcasper@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11829 +/- ##
==========================================
+ Coverage 51.19% 51.29% +0.10%
==========================================
Files 715 715
Lines 45081 45170 +89
==========================================
+ Hits 23079 23171 +92
Misses 19803 19803
+ Partials 2199 2196 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes misaligned CLI table output by replacing the text/tabwriter-based table renderer with a custom renderer that can word-wrap the last column to the detected terminal width, keeping continuation lines aligned under the correct column.
Changes:
- Replaced the table output implementation with a manual renderer that computes column widths and wraps the last column when terminal width is known.
- Added tests validating last-column wrapping behavior (including unbreakable tokens) and no-wrap behavior when terminal width is unknown.
- Promoted
golang.org/x/term(andgithub.com/hashicorp/go-version) to direct dependencies ingo.mod.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pkg/cli/output/table.go | New manual table renderer with terminal-width detection and last-column wrapping. |
| pkg/cli/output/table_test.go | Added unit tests covering wrapping/no-wrapping scenarios. |
| go.mod | Updated direct dependencies to include golang.org/x/term (and go-version). |
| func padRight(s string, width int) string { | ||
| if len(s) >= width { | ||
| return s | ||
| } | ||
| return s + strings.Repeat(" ", width-len(s)) |
| lines = append(lines, word[:width]) | ||
| word = word[width:] |
| var lines []string | ||
| current := "" | ||
| for _, word := range strings.Fields(s) { | ||
| // Break words that are themselves longer than the column width. |
Agent-Logs-Url: https://github.com/radius-project/radius/sessions/e0470685-5721-4a91-b3e1-ac6fc8a2e1af Co-authored-by: zachcasper <30731731+zachcasper@users.noreply.github.com>
Radius functional test overviewClick here to see the test run details
Test Status⌛ Building Radius and pushing container images for functional tests... |
text/tabwriter-based renderer with manual line-by-line renderer that wraps the last column to terminal width.golang.org/x/term; pad continuation lines.utf8.RuneCountInStringfor column-width and padding calculations so multi-byte UTF-8 stays aligned.strings.Fields-based wrap with a rune-walking wrapper that preserves internal whitespace and only drops trailing whitespace at wrap boundaries.