fix: wrap wide license columns to the terminal width - #556
Open
Eljees wants to merge 1 commit into
Open
Conversation
A package carrying several licenses makes the row far wider than the terminal, so the table output wraps at arbitrary points and becomes hard to read. Limit the license columns to half the terminal width, letting go-pretty wrap inside the column instead of pushing the row off screen. The width is only applied when stdout is a terminal, so piped and redirected output keeps exactly the shape it has today. Signed-off-by: Eljees <3.14hell@gmail.com>
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.
Fixes #276
Problem
A package that carries several licenses makes the license cell very wide, so the row runs far past the edge of the terminal and the table becomes hard to read (the issue shows a
jasper-libsrow spilling across the screen).The tables are built with go-pretty but no column width is configured anywhere, so a cell is rendered at its natural width regardless of how wide the terminal actually is.
Change
Adds a small helper in
cmd/grant/cli/internal:TerminalWidth()— the width of the terminal attached to stdout, or0when stdout is not a terminal or the size can't be determined (golang.org/x/termis already a dependency).WrapWideColumns(t, columns...)— setsWidthMaxon the named columns so go-pretty wraps inside the column instead of widening the row.Applied to the six tables that carry a license column (
output.go×2,list.go×3,check.go×1), matched by header name rather than index.Two deliberate properties:
The share of the terminal given to the license column (half, with a floor of 20 columns) is a heuristic — happy to change the split or make it configurable if you'd prefer something else.
Tests
wrappedColumnWidthis a pure function so the width policy is testable without a TTY;TestWrappedColumnWidthcovers the unknown-width, negative, wide-terminal and narrow-terminal cases.go build ./...is clean across the repo. I wasn't able to finish a fullgo test ./...locally — the machine I had available couldn't get through the CLI integration suite in reasonable time — so I'd lean on CI for that.