Fit table output to the terminal width - #72
Merged
Conversation
tabwriter sizes a column by its widest cell, so a 400 character DNSKEY value padded the CONTENT cell of every row and pushed TTL and REGIONS past the right edge of the screen. One long value broke the alignment of the whole table. The columns before the last one now shrink to fit the terminal, and a value that no longer fits ends with an ellipsis. The last column never shrinks, because tabwriter does not pad the last cell of a row. A writer that is not a terminal keeps every value in full, so a pipe, a redirect, --json, and --format stay lossless.
A last column wider than the terminal never shrinks, so the columns before it were giving up their values for nothing. The FIELD labels of a detail table were cut to "Syste..." while the value they describe stayed whole. Leave the table alone in that case, and skip the row copy when the table already fits. Fold the terminal probe into terminalWidth next to IsTerminal, so the *os.File assertion has one home, and count runes with the standard library instead of a local helper.
The last column test used a FIELD label of seven characters, which is under the floor and can never be cut. It passed whatever the code did.
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.
Table output is now cut to the width of the terminal. A long value, for example a DNSKEY record, padded the CONTENT cell of every row and pushed the TTL and the REGIONS columns off the screen, so one long value broke the alignment of the whole table. The columns before the last one now shrink to fit, and a value that does not fit ends with
.... The last column never shrinks, because tabwriter does not pad the last cell of a row.Only a terminal cuts the table. Redirected output,
--json,--format, and the single-resourcegetcommands still return the full value.Closes #13
🔍 QA
Scenario: List the records of a signed zone
dnsimple records list <zone>on a zone that has DNSKEY records...., and the TTL and the REGIONS columns stay on the same line as their record.dnsimple records list <zone> | cat. Confirm the output carries the full values.dnsimple records get <zone> <record-id>for a DNSKEY record. Confirm the detail table shows the full content.📋 Deployment Pre/Post tasks
N/A
N/A