summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith.r@gmail.com>2016-07-31 21:33:30 -0700
committerGitHub <noreply@github.com>2016-07-31 21:33:30 -0700
commitb1cf9575050de7ae1d65f38b6dea297e5cee6fba (patch)
tree8b06ee116568497dbd4fe58c623db9385a5ce13a
parentfb23a1e4ec0eb4b76fe30b3f86f1ba05e934f369 (diff)
parent2faf7b1f5414a8abb812c7dca442473058f00ec1 (diff)
Merge pull request #556 from avdd/master
configurable null format
-rwxr-xr-xpgcli/main.py12
-rw-r--r--pgcli/packages/expanded.py4
-rw-r--r--pgcli/packages/tabulate.py3
3 files changed, 10 insertions, 9 deletions
diff --git a/pgcli/main.py b/pgcli/main.py
index 2a9b7ae3..46dd31df 100755
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -132,8 +132,8 @@ class PGCli(object):
self.cli_style = c['colors']
self.wider_completion_menu = c['main'].as_bool('wider_completion_menu')
self.less_chatty = c['main'].as_bool('less_chatty')
+ self.null_string = c['main'].get('null_string', '<null>')
self.prompt_format = c['main'].get('prompt', self.default_prompt)
-
self.on_error = c['main']['on_error'].upper()
self.completion_refresher = CompletionRefresher()
@@ -561,7 +561,7 @@ class PGCli(object):
max_width = None
formatted = format_output(
- title, cur, headers, status, self.table_format,
+ title, cur, headers, status, self.table_format, self.null_string,
self.pgspecial.expanded_output, max_width)
output.extend(formatted)
@@ -761,21 +761,21 @@ def obfuscate_process_password():
setproctitle.setproctitle(process_title)
-def format_output(title, cur, headers, status, table_format, expanded=False, max_width=None):
+def format_output(title, cur, headers, status, table_format, missingval='<null>', expanded=False, max_width=None):
output = []
if title: # Only print the title if it's not None.
output.append(title)
if cur:
headers = [utf8tounicode(x) for x in headers]
if expanded and headers:
- output.append(expanded_table(cur, headers))
+ output.append(expanded_table(cur, headers, missingval))
else:
tabulated, rows = tabulate(cur, headers, tablefmt=table_format,
- missingval='<null>')
+ missingval=missingval)
if (max_width and rows and
content_exceeds_width(rows[0], max_width) and
headers):
- output.append(expanded_table(rows, headers))
+ output.append(expanded_table(rows, headers, missingval))
else:
output.append(tabulated)
if status: # Only print the status if it's not None.
diff --git a/pgcli/packages/expanded.py b/pgcli/packages/expanded.py
index 03809c7c..a6cde000 100644
--- a/pgcli/packages/expanded.py
+++ b/pgcli/packages/expanded.py
@@ -3,7 +3,7 @@ from .tabulate import _text_type
def pad(field, total, char=u" "):
return field + (char * (total - len(field)))
-def expanded_table(rows, headers):
+def expanded_table(rows, headers, missingval=u""):
header_len = max([len(x) for x in headers])
max_row_len = 0
results = []
@@ -19,7 +19,7 @@ def expanded_table(rows, headers):
max_row_len = row_len
for header, value in zip(padded_headers, row):
- value = '<null>' if value is None else value
+ value = missingval if value is None else value
row_result.append((u"%s" % header) + " " + (u"%s" % value).strip())
results.append('\n'.join(row_result))
diff --git a/pgcli/packages/tabulate.py b/pgcli/packages/tabulate.py
index df668f47..1aec0aef 100644
--- a/pgcli/packages/tabulate.py
+++ b/pgcli/packages/tabulate.py
@@ -889,7 +889,8 @@ def tabulate(tabular_data, headers=[], tablefmt="simple",
_text_type_encode = lambda x: _text_type(utf8tounicode(x))
plain_text = '\n'.join(['\t'.join(map(_text_type_encode, headers))] + \
['\t'.join(map(_text_type_encode, row)) for row in list_of_lists])
- has_invisible = re.search(_invisible_codes, plain_text)
+ has_invisible = (re.search(_invisible_codes, plain_text) or
+ re.search(_invisible_codes, missingval))
if has_invisible:
width_fn = _visible_width
else: