Skip to content

Commit e7d6123

Browse files
authored
Implement "folded table" output, as an opt-in feature for all tabular outputs (#1231)
2 parents 940c362 + 19806f3 commit e7d6123

File tree

12 files changed

+581
-13
lines changed

12 files changed

+581
-13
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### Enhancements
2+
3+
* When using table output on narrow terminals, the Globus CLI will now stack
4+
table elements in a new "folded table" layout. This behavior is only used
5+
when the output device is a TTY. To disable the new output altogether, users
6+
can set `GLOBUS_CLI_FOLD_TABLES=0`.

src/globus_cli/termio/_display.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
import click
77
import globus_sdk
88

9-
from .context import outformat_is_json, outformat_is_text, outformat_is_unix
9+
from .context import (
10+
fold_tables,
11+
outformat_is_json,
12+
outformat_is_text,
13+
outformat_is_unix,
14+
)
1015
from .field import Field
1116
from .printers import (
1217
CustomPrinter,
18+
FoldedTablePrinter,
1319
JsonPrinter,
1420
Printer,
1521
RecordListPrinter,
@@ -172,7 +178,10 @@ def _resolve_printer(
172178

173179
_assert_iterable(data)
174180
if text_mode == self.TABLE:
175-
return TablePrinter(fields)
181+
if fold_tables():
182+
return FoldedTablePrinter(fields)
183+
else:
184+
return TablePrinter(fields)
176185
if text_mode == self.RECORD_LIST:
177186
return RecordListPrinter(fields)
178187

src/globus_cli/termio/context.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,8 @@ def term_is_interactive() -> bool:
108108
return True
109109

110110
return os.getenv("PS1") is not None
111+
112+
113+
def fold_tables() -> bool | None:
114+
val = os.getenv("GLOBUS_CLI_FOLD_TABLES")
115+
return val is None or utils.str2bool(val)

src/globus_cli/termio/printers/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .base import Printer
22
from .custom_printer import CustomPrinter
3+
from .folded_table_printer import FoldedTablePrinter
34
from .json_printer import JsonPrinter
45
from .record_printer import RecordListPrinter, RecordPrinter
56
from .table_printer import TablePrinter
@@ -11,6 +12,7 @@
1112
"JsonPrinter",
1213
"UnixPrinter",
1314
"TablePrinter",
15+
"FoldedTablePrinter",
1416
"RecordPrinter",
1517
"RecordListPrinter",
1618
)

0 commit comments

Comments
 (0)