Skip to content

fix: make table output fit terminal width - #8

Merged
Amzani merged 3 commits into
apideck-libraries:mainfrom
srbhr:fix/table-output-terminal-width
Apr 16, 2026
Merged

fix: make table output fit terminal width#8
Amzani merged 3 commits into
apideck-libraries:mainfrom
srbhr:fix/table-output-terminal-width

Conversation

@srbhr

@srbhr srbhr commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

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.

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.
@srbhr
srbhr marked this pull request as ready for review April 15, 2026 11:53
Copilot AI review requested due to automatic review settings April 15, 2026 11:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/output/table.go Outdated
Comment thread internal/output/table.go Outdated
Comment thread internal/output/table.go Outdated
Comment thread internal/output/formatter_test.go Outdated
Amzani and others added 2 commits April 15, 2026 13:52
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.
@Amzani
Amzani merged commit ab89340 into apideck-libraries:main Apr 16, 2026
1 check passed
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.

3 participants