fix: make table output fit terminal width - #8
Merged
Amzani merged 3 commits intoApr 16, 2026
Conversation
The table formatter had no concept of terminal width — nested objects (addresses, line items) were dumped as raw JSON, pushing columns to hundreds of characters. Now columns are capped, truncated with ellipsis, and budgeted to fit the terminal. Complex nested columns are auto-pruned when there are too many to display readably. Scalar fields are sorted before complex ones for better default column ordering.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the CLI table formatter to keep output within terminal width by capping/shrinking columns, truncating long values with an ellipsis, and pruning/sorting columns to prioritize readable scalar fields over complex nested data.
Changes:
- Add terminal-width aware column budgeting, truncation, and complex-field pruning in table output.
- Sort auto-detected fields so scalar columns appear before nested/complex columns.
- Add unit tests for truncation/budgeting and a table-width regression test.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| internal/output/table.go | Adds terminal-width detection, complex-field pruning, column budgeting, truncation, and rune-aware padding. |
| internal/output/rows.go | Adds scalar-before-complex stable sorting for auto-detected fields and an isComplex helper. |
| internal/output/formatter_test.go | Adds tests for truncation/budgeting and verifies table output line length constraints. |
| go.mod | Promotes github.com/charmbracelet/x/term to a direct dependency for terminal sizing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Amzani
approved these changes
Apr 15, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Address PR review feedback: - Column width calculation now uses utf8.RuneCountInString instead of len() (byte count) so non-ASCII text is measured correctly. - Terminal width is derived from the formatter's io.Writer (when it is an *os.File TTY) instead of always reading os.Stdout. A widthFn field allows tests to inject a fixed width, eliminating environment dependence. - Fix padRight comment to accurately say "runes" instead of "display width". - TestTableFormatterTruncatesLongValues now uses an injected width of 80 so it is deterministic regardless of the caller's terminal size.
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.
The table formatter had no concept of terminal width — nested objects (addresses, line items) were dumped as raw JSON, pushing columns to hundreds of characters. Now columns are capped, truncated with ellipsis, and budgeted to fit the terminal. Complex nested columns are auto-pruned when there are too many to display readably. Scalar fields are sorted before complex ones for better default column ordering.