1
1
mirror of https://github.com/dbcli/pgcli.git synced 2024-11-09 16:34:32 +03:00

Merge pull request #621 from dbcli/koljonen/show_transaction_status

Add transaction status to toolbar
This commit is contained in:
Irina Truong 2016-12-12 15:06:51 -08:00 committed by GitHub
commit 4edd124c0d
4 changed files with 25 additions and 2 deletions

View File

@ -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),

View File

@ -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]

View File

@ -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.

View File

@ -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...'))