Skip to content

Conversation

@sirosen
Copy link
Member

@sirosen sirosen commented Dec 31, 2025

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

a b c d e f

to

a c e
b d f

or

a d
b e
c f

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.

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.
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.

1 participant