Implement "folded table" output, as an opt-in feature for all tabular outputs#1231
Draft
sirosen wants to merge 4 commits intoglobus:mainfrom
Draft
Implement "folded table" output, as an opt-in feature for all tabular outputs#1231sirosen wants to merge 4 commits intoglobus:mainfrom
sirosen wants to merge 4 commits intoglobus:mainfrom
Conversation
This is an alternative output mode which, when selected, prints tabular data with row separators. Based on terminal width detection, the output can be "folded" to stack up adjacent elements into columns, making rows more horizontally compact. The table folding first tries by halves, then thirds, and finally resorts to folding by N where N is the number of columns.
Also make the styling fallback to a line-oriented style when output is not an interactive terminal.
Unit tests of the Row class and some higher level integration tests of the printer itself to ensure it produces proper tabular output both with and without folding enabled.
'GLOBUS_CLI_FOLD_TABLES=1' enables table folding for all tabular outputs. This can be used to preview the behavior and, in the future, to opt-out of folded table output for the entire CLI.
801637d to
54315b6
Compare
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.
This could be viewed as an alternative implementation / reimplementation of our table output printer.
Similar to the current table output, it loads the data to print into a data structure which represents our desired output.
Unlike the current table output, each row is treated as a meaningful data structure as well.
Instead of a grid of cells for the whole table, a table is a list of rows, each of which contains a grid.
Rows and tables are not responsible for correctness invariants like "every row has the same layout" -- the enforcement of such rules is left solely to the higher-level printer.
Rows define "folding", which is an accordion-like fold that converts from
to
or
and so forth for different fold sizes.
Rows do not support folding when they are already folded -- only a 1-height row can be folded.
As such, Rows and Tables (lists of Rows) are immutable, and the folding methods produce net-new rows and new tables.
The printer handles them as such, and can therefore compare a "fold by 2" table with a "fold by 3" table.
With the "folding table" implemented and checked against terminal width to determine how much/if it should fold, there is the matter of output formatting for the rows.
Each row knows how to format itself, and accepts a set of "style" flags (an enum) to control specifics.
The same "style" flags can control the printing of separator lines for the header and foot of the table.
Finally, there is the matter of control.
When the environment is not interactive (e.g., a pipeline), folding is always disabled.
The table folding output is off by default, but can be enabled as a replacement for all table printing by setting the new env var
GLOBUS_CLI_FOLD_TABLES=1.The intent, in this PR, is that the new folded table would fully replace our table output in the future, and users could opt out of the behavior with
GLOBUS_CLI_FOLD_TABLES=0.When a table is not folded, the output is almost identical to our current non-folded table. This is intentional.