summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIrina Truong <i.chernyavska@gmail.com>2016-12-12 15:06:51 -0800
committerGitHub <noreply@github.com>2016-12-12 15:06:51 -0800
commit4edd124c0dcbf24ff898eaac855f0a76c7c1e8bb (patch)
tree5d90934ca6b9ab9ab6dc8a2b53b7f1426e389f19
parenta9352bdb221b7df0c3bec67167e1a8f73d8a2514 (diff)
parent466b8e74be8904f8443882f0c69f82239e01c919 (diff)
Merge pull request #621 from dbcli/koljonen/show_transaction_status
Add transaction status to toolbar
-rwxr-xr-xpgcli/main.py4
-rw-r--r--pgcli/pgclirc2
-rw-r--r--pgcli/pgexecute.py12
-rw-r--r--pgcli/pgtoolbar.py9
4 files changed, 25 insertions, 2 deletions
diff --git a/pgcli/main.py b/pgcli/main.py
index cfe14318..bb3238b6 100755
--- a/pgcli/main.py
+++ b/pgcli/main.py
@@ -498,7 +498,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 cc658b66..1440593c 100644
--- a/pgcli/pgclirc
+++ b/pgcli/pgclirc
@@ -124,6 +124,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 #00ff5f bold'
+Token.Toolbar.Transaction.Failed = 'bg:#222222 #ff005f 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 84db715d..be720074 100644
--- a/pgcli/pgtoolbar.py
+++ b/pgcli/pgtoolbar.py
@@ -10,7 +10,8 @@ def _get_vi_mode(cli):
InputMode.INSERT_MULTIPLE: 'M',
}[cli.vi_state.input_mode]
-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.
"""
@@ -43,6 +44,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...'))