summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmjith Ramanujam <amjith@newrelic.com>2014-12-19 20:57:36 -0800
committerAmjith Ramanujam <amjith@newrelic.com>2014-12-19 20:57:36 -0800
commitc66f9a79e1ff98f123018305cabe22732a33b1b2 (patch)
tree6f89f40d8e0224d01fe9c82a0364b21415808392
parentca36dba63a43cfcbd605d1e6fd3810f664ca1f7b (diff)
Add pager support for output.
-rw-r--r--TODO3
-rwxr-xr-xpgcli/main.py6
2 files changed, 6 insertions, 3 deletions
diff --git a/TODO b/TODO
index 793be42b..b0125997 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,6 @@
# vi: ft=vimwiki
* [ ] Fix: SELECT id, <tab> FROM django_migrations; - Auto-completion for the second column name is broken. Find the last keyword and use it for completion.
-* [ ] Use a pager to display the output. (Check Click's document).
+* [ ] Bottom status bar is cut-off in half pane. Figure out how to fix that.
* [ ] Default host should not be set to localhost. Since it causes problems in IPv6 machines. Need to research this one further.
* [ ] Column completion for nested sql.
* [ ] Add JOIN to the list of keywords and provide proper autocompletion for it.
@@ -27,6 +27,7 @@
* [ ] New Feature List - Write the current version to config file. At launch if the version has changed, display the changelog between the two versions.
* [o] Separate the column completions to be table specific. (SELECT, INSERT, UPDATE)
* [X] Write a doc about how to run it in develop mode. (pip install -e .)
+* [X] Use a pager to display the output. (Check Click's document).
* [X] Column completion for simple SELECT.
* [X] Column completion for simple INSERT.
* [X] Column completion for simple UPDATE.
diff --git a/pgcli/main.py b/pgcli/main.py
index db1f9001..ce4c4560 100755
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -87,11 +87,13 @@ def cli(database, user, password, host, port):
raise Exit
try:
res = pgexecute.run(document.text)
+ output = []
for rows, headers, status in res:
if rows:
- print(tabulate(rows, headers, tablefmt='psql'))
+ output.append(tabulate(rows, headers, tablefmt='psql'))
if status: # Only print the status if it's not None.
- print(status)
+ output.append(status)
+ click.echo_via_pager('\n'.join(output))
except Exception as e:
click.secho(e.message, err=True, fg='red')