summaryrefslogtreecommitdiffstats
path: root/pgcli/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'pgcli/main.py')
-rw-r--r--pgcli/main.py14
1 files changed, 13 insertions, 1 deletions
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