diff options
author | Paweł Sacawa <pawelsacawa@gmail.com> | 2021-05-02 18:12:13 -0400 |
---|---|---|
committer | Paweł Sacawa <pawelsacawa@gmail.com> | 2021-05-02 18:18:35 -0400 |
commit | 8de796c59c70bc673dd05928514376e64a5609d4 (patch) | |
tree | 82755c6e467042537912e17ff31c14fc796d87a6 /pgcli | |
parent | 954b8c3902b251aeb7a576e275393a2c61644286 (diff) |
Fix: ANSI escape codes in first line make the cli choose expanded output incorrectly...
The format_output chooses to output as a table or in the expanded
format on the basis of the length of the first line of the table
formatter (`len`). However, this first line contains a lot of ANSI
excape codes, so this comparison is wrong, and the expanded mode
is used either way. This patch strips these escape codes before the
comparison.
Diffstat (limited to 'pgcli')
-rw-r--r-- | pgcli/main.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/pgcli/main.py b/pgcli/main.py index e1c6fc71..05d97e73 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -26,6 +26,7 @@ keyring = None # keyring will be loaded later from cli_helpers.tabular_output import TabularOutputFormatter from cli_helpers.tabular_output.preprocessors import align_decimals, format_numbers +from cli_helpers.utils import strip_ansi import click try: @@ -1487,7 +1488,7 @@ def format_output(title, cur, headers, status, settings): formatted = iter(formatted.splitlines()) first_line = next(formatted) formatted = itertools.chain([first_line], formatted) - if not expanded and max_width and len(first_line) > max_width and headers: + if not expanded and max_width and len(strip_ansi(first_line)) > max_width and headers: formatted = formatter.format_output( cur, headers, format_name="vertical", column_types=None, **output_kwargs ) |