diff options
author | Amjith Ramanujam <amjith@newrelic.com> | 2014-12-15 22:04:03 -0800 |
---|---|---|
committer | Amjith Ramanujam <amjith@newrelic.com> | 2014-12-15 22:04:03 -0800 |
commit | 312770e10e736f7cdbebda6dc6c5577cfe21a3e6 (patch) | |
tree | dffa47c07b598491156a268ebb5800fe2113fe2a | |
parent | b0bea4dc500493825128bf41b44cb9b973d1ce55 (diff) |
F3 to toggle multi-line.
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | pgcli/key_bindings.py | 8 | ||||
-rwxr-xr-x | pgcli/main.py | 2 | ||||
-rw-r--r-- | pgcli/pgline.py | 8 | ||||
-rw-r--r-- | pgcli/pgtoolbar.py | 14 |
5 files changed, 27 insertions, 7 deletions
@@ -1,5 +1,4 @@ # vi: ft=vimwiki -* [ ] Enable multi-line mode via a keybinding. * [ ] Separate the column completions to be table specific. * [ ] Improve the smart completion for Insert statement. (Needs table specific columns) * [ ] Improve the smart completion for Update statement. (Needs table specific columns) @@ -17,6 +16,7 @@ * [ ] Detect a '.' and parse the word before it and get it's real name. * [ ] Refactor the execution and output into a separate class. * [ ] Create a class for the config and make it easy to access. +* [X] Enable multi-line mode via a keybinding. * [X] Pressing enter should just pop another prompt. * [X] Implement \?. * [X] Automate the release procedure. diff --git a/pgcli/key_bindings.py b/pgcli/key_bindings.py index 34d0ad51..949fa334 100644 --- a/pgcli/key_bindings.py +++ b/pgcli/key_bindings.py @@ -13,3 +13,11 @@ def pgcli_bindings(registry, cli_ref): Enable/Disable SmartCompletion Mode. """ line.completer.smart_completion = not line.completer.smart_completion + + @handle(Keys.F3) + def _(event): + """ + Enable/Disable Multiline Mode. + """ + #import pdb; pdb.set_trace() + line.always_multiline = not line.always_multiline diff --git a/pgcli/main.py b/pgcli/main.py index e359757c..9fed06a7 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -65,7 +65,7 @@ def cli(database, user, password, host, port): completer.extend_table_names(pgexecute.tables()) completer.extend_column_names(pgexecute.all_columns()) completer.extend_database_names(pgexecute.databases()) - line = PGLine(completer=completer, + line = PGLine(always_multiline=False, completer=completer, history=FileHistory(os.path.expanduser('~/.pgcli-history'))) cli = CommandLineInterface(style=PGStyle, layout=layout, line=line, key_binding_factories=[emacs_bindings, pgcli_bindings]) diff --git a/pgcli/pgline.py b/pgcli/pgline.py index e231f33e..5c4f0496 100644 --- a/pgcli/pgline.py +++ b/pgcli/pgline.py @@ -1,7 +1,8 @@ from prompt_toolkit.line import Line class PGLine(Line): - def __init__(self, *args, **kwargs): + def __init__(self, always_multiline, *args, **kwargs): + self.always_multiline = always_multiline super(self.__class__, self).__init__(*args, **kwargs) @property @@ -10,7 +11,10 @@ class PGLine(Line): Dynamically determine whether we're in multiline mode. """ - if _multiline_exception(self.text): + if not self.always_multiline: + return False + + if self.always_multiline and _multiline_exception(self.text): return False return True diff --git a/pgcli/pgtoolbar.py b/pgcli/pgtoolbar.py index 1866a42b..058db4a1 100644 --- a/pgcli/pgtoolbar.py +++ b/pgcli/pgtoolbar.py @@ -11,9 +11,17 @@ class PGToolbar(Toolbar): result = TokenList() result.append((self.token, ' ')) if cli.line.completer.smart_completion: - result.append((self.token.On, '[F2] Smart Completion (on)')) + result.append((self.token.On, '[F2] Smart Completion: ON ')) else: - result.append((self.token.Off, '[F2] Smart Completion (off)')) + result.append((self.token.Off, '[F2] Smart Completion: OFF ')) + + if cli.line.always_multiline: + result.append((self.token.On, '[F3] Multiline: ON')) + else: + result.append((self.token.Off, '[F3] Multiline: OFF')) + + if cli.line.always_multiline: + result.append((self.token, + ' (Semi-colon [;] will end the line)')) - #result.append((self.token, ' ' * (width - len(result)))) return result |