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:
commit
4edd124c0d
@ -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),
|
||||
|
@ -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]
|
||||
|
@ -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.
|
||||
|
@ -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...'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user