diff options
author | pmav99 <pmav99@users.noreply.github.com> | 2020-04-23 20:17:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-23 10:17:40 -0700 |
commit | bcb0c8bce776a5eba9f5425c57c2ec8385f10e94 (patch) | |
tree | 599c7390a8707b028accd5246e3f9707e016fc80 | |
parent | 3071de14f55f7ea1a3df2dd5f42800363e225d2a (diff) |
Add support for using pspg as the pager. (#1173)
* Stop printing "status" when table_format is "csv"
* Use the "unix" dialect on *nix for CSV output.
* Use a pager when `pspg` has been configured with CSV "table_format".
Fix #1102
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | changelog.rst | 1 | ||||
-rw-r--r-- | pgcli/main.py | 14 |
3 files changed, 15 insertions, 1 deletions
@@ -107,6 +107,7 @@ Contributors: * Yoni Nakache(lazydba247) * Gantsev Denis * Stephano Paraskeva + * Panos Mavrogiorgos (pmav99) Creator: -------- diff --git a/changelog.rst b/changelog.rst index 3c8d8c20..3db7fec7 100644 --- a/changelog.rst +++ b/changelog.rst @@ -5,6 +5,7 @@ Features: --------- * Make the output more compact by removing the empty newline. (Thanks: `laixintao`_) +* Add support for using [pspg](https://github.com/okbob/pspg) as a pager (#1102) Bug fixes: ---------- diff --git a/pgcli/main.py b/pgcli/main.py index a2128619..cc3d58c4 100644 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -18,6 +18,7 @@ import functools import humanize import datetime as dt import itertools +import platform from time import time, sleep from codecs import open @@ -1074,6 +1075,8 @@ class PGCli(object): def echo_via_pager(self, text, color=None): if self.pgspecial.pager_config == PAGER_OFF or self.watch_command: click.echo(text, color=color) + elif "pspg" in os.environ["PAGER"] and self.table_format == "csv": + click.echo_via_pager(text, color) elif self.pgspecial.pager_config == PAGER_LONG_OUTPUT: lines = text.split("\n") @@ -1426,6 +1429,14 @@ def format_output(title, cur, headers, status, settings): if not settings.floatfmt: output_kwargs["preprocessors"] = (align_decimals,) + if table_format == "csv": + # The default CSV dialect is "excel" which is not handling newline values correctly + # Nevertheless, we want to keep on using "excel" on Windows since it uses '\r\n' + # as the line terminator + # https://github.com/dbcli/pgcli/issues/1102 + dialect = "excel" if platform.system() == "Windows" else "unix" + output_kwargs["dialect"] = dialect + if title: # Only print the title if it's not None. output.append(title) @@ -1464,7 +1475,8 @@ def format_output(title, cur, headers, status, settings): output = itertools.chain(output, formatted) - if status: # Only print the status if it's not None. + # Only print the status if it's not None and we are not producing CSV + if status and table_format != "csv": output = itertools.chain(output, [status]) return output |