From 8de796c59c70bc673dd05928514376e64a5609d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Sacawa?= Date: Sun, 2 May 2021 18:12:13 -0400 Subject: 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. --- pgcli/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ) -- cgit v1.2.3 From 773f69ba432c995344748b427ba3902c5ee6e665 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Sacawa?= Date: Sun, 2 May 2021 18:27:55 -0400 Subject: Modify changelog --- AUTHORS | 1 + changelog.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 8018acf6..bcfba6a3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -117,6 +117,7 @@ Contributors: * Eero Ruohola (ruohola) * Miroslav Šedivý (eumiro) * Eric R Young (ERYoung11) + * Paweł Sacawa (psacawa) Creator: -------- diff --git a/changelog.rst b/changelog.rst index bc1ad77b..fdf0701c 100644 --- a/changelog.rst +++ b/changelog.rst @@ -16,6 +16,7 @@ Bug fixes: * Fix comments being lost in config when saving a named query. (#1240) * Fix IPython magic for ipython-sql >= 0.4.0 * Fix pager not being used when output format is set to csv. (#1238) +* Fix ANSI escape codes in first line make the cli choose expanded output incorrectly 3.1.0 ===== -- cgit v1.2.3 From 2fe94c38b4e2fb3f724598b15c1dca280961a84e Mon Sep 17 00:00:00 2001 From: Amjith Ramanujam Date: Wed, 5 May 2021 21:01:12 -0700 Subject: Black formatting. --- pgcli/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pgcli/main.py b/pgcli/main.py index 05d97e73..ecf041bb 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -1248,8 +1248,7 @@ def cli( else: print("Config file is now located at", config_full_path) print( - "Please move the existing config file ~/.pgclirc to", - config_full_path, + "Please move the existing config file ~/.pgclirc to", config_full_path, ) if list_dsn: try: @@ -1488,7 +1487,12 @@ 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(strip_ansi(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 ) -- cgit v1.2.3