diff options
author | Joakim Koljonen <koljonen@outlook.com> | 2016-12-07 04:27:39 +0100 |
---|---|---|
committer | Joakim Koljonen <koljonen@outlook.com> | 2016-12-07 04:39:03 +0100 |
commit | f8b1647ae807a459dddcc10e569652ed955e158b (patch) | |
tree | 62d808a6e5cdcdd52a4327f53270a810c88142c8 | |
parent | d964c74bc414f8c51d4b146511f6dede93aa1c65 (diff) |
Add transaction status to toolbar
-rwxr-xr-x | pgcli/main.py | 4 | ||||
-rw-r--r-- | pgcli/pgclirc | 2 | ||||
-rw-r--r-- | pgcli/pgexecute.py | 12 | ||||
-rw-r--r-- | pgcli/pgtoolbar.py | 9 |
4 files changed, 25 insertions, 2 deletions
diff --git a/pgcli/main.py b/pgcli/main.py index 07417b8b..1bc673d5 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -497,7 +497,9 @@ class PGCli(object): return [(Token.Continuation, '.' * (width - 1) + ' ')] get_toolbar_tokens = create_toolbar_tokens_func( - lambda: self.vi_mode, self.completion_refresher.is_refreshing) + lambda: self.vi_mode, self.completion_refresher.is_refreshing, + self.pgexecute.failed_transaction, + self.pgexecute.valid_transaction) layout = create_prompt_layout( lexer=PygmentsLexer(PostgresLexer), diff --git a/pgcli/pgclirc b/pgcli/pgclirc index 3ff831c4..df4ea27d 100644 --- a/pgcli/pgclirc +++ b/pgcli/pgclirc @@ -120,6 +120,8 @@ Token.Toolbar.Search.Text = 'nobold' Token.Toolbar.System = 'noinherit bold' Token.Toolbar.Arg = 'noinherit bold' Token.Toolbar.Arg.Text = 'nobold' +Token.Toolbar.Transaction.Valid = "bg:#222222 #aaffcc bold" +Token.Toolbar.Transaction.Failed = "bg:#222222 #ffbbbb bold" # Named queries are queries you can execute by name. [named queries] diff --git a/pgcli/pgexecute.py b/pgcli/pgexecute.py index 94ab386f..9c6167ef 100644 --- a/pgcli/pgexecute.py +++ b/pgcli/pgexecute.py @@ -230,6 +230,18 @@ class PGExecute(object): else: return json_data + + def failed_transaction(self): + status = self.conn.get_transaction_status() + return status == ext.TRANSACTION_STATUS_INERROR + + + def valid_transaction(self): + status = self.conn.get_transaction_status() + return (status == ext.TRANSACTION_STATUS_ACTIVE or + status == ext.TRANSACTION_STATUS_INTRANS) + + def run(self, statement, pgspecial=None, exception_formatter=None, on_error_resume=False): """Execute the sql in the database and return the results. diff --git a/pgcli/pgtoolbar.py b/pgcli/pgtoolbar.py index 74144bb9..4629a36d 100644 --- a/pgcli/pgtoolbar.py +++ b/pgcli/pgtoolbar.py @@ -2,7 +2,8 @@ from pygments.token import Token from prompt_toolkit.enums import DEFAULT_BUFFER -def create_toolbar_tokens_func(get_vi_mode_enabled, get_is_refreshing): +def create_toolbar_tokens_func(get_vi_mode_enabled, get_is_refreshing, + failed_transaction, valid_transaction): """ Return a function that generates the toolbar tokens. """ @@ -35,6 +36,12 @@ def create_toolbar_tokens_func(get_vi_mode_enabled, get_is_refreshing): else: result.append((token.On, '[F4] Emacs-mode')) + if failed_transaction(): + result.append((token.Transaction.Failed, ' Failed transaction')) + + if valid_transaction(): + result.append((token.Transaction.Valid, ' Transaction')) + if get_is_refreshing(): result.append((token, ' Refreshing completions...')) |