summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpmav99 <pmav99@users.noreply.github.com>2020-04-23 20:17:40 +0300
committerGitHub <noreply@github.com>2020-04-23 10:17:40 -0700
commitbcb0c8bce776a5eba9f5425c57c2ec8385f10e94 (patch)
tree599c7390a8707b028accd5246e3f9707e016fc80
parent3071de14f55f7ea1a3df2dd5f42800363e225d2a (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--AUTHORS1
-rw-r--r--changelog.rst1
-rw-r--r--pgcli/main.py14
3 files changed, 15 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 4c2ab3f0..8812c7ad 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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