diff options
-rw-r--r-- | pgcli/key_bindings.py | 9 | ||||
-rwxr-xr-x | pgcli/main.py | 15 | ||||
-rw-r--r-- | setup.py | 2 |
3 files changed, 17 insertions, 9 deletions
diff --git a/pgcli/key_bindings.py b/pgcli/key_bindings.py index e13f3c73..2a365e0e 100644 --- a/pgcli/key_bindings.py +++ b/pgcli/key_bindings.py @@ -1,4 +1,5 @@ import logging +from prompt_toolkit.enums import EditingMode from prompt_toolkit.keys import Keys from prompt_toolkit.key_binding.manager import KeyBindingManager from prompt_toolkit.filters import Condition @@ -18,8 +19,7 @@ def pgcli_bindings(get_vi_mode_enabled, set_vi_mode_enabled): enable_open_in_editor=True, enable_system_bindings=True, enable_search=True, - enable_abort_and_exit_bindings=True, - enable_vi_mode=Condition(lambda cli: get_vi_mode_enabled())) + enable_abort_and_exit_bindings=True) @key_binding_manager.registry.add_binding(Keys.F2) def _(event): @@ -45,7 +45,10 @@ def pgcli_bindings(get_vi_mode_enabled, set_vi_mode_enabled): Toggle between Vi and Emacs mode. """ _logger.debug('Detected F4 key.') - set_vi_mode_enabled(not get_vi_mode_enabled()) + vi_mode = not get_vi_mode_enabled() + set_vi_mode_enabled(vi_mode) + + event.cli.editing_mode = EditingMode.VI if vi_mode else EditingMode.EMACS @key_binding_manager.registry.add_binding(Keys.Tab) def _(event): diff --git a/pgcli/main.py b/pgcli/main.py index bda2a13d..90468f91 100755 --- a/pgcli/main.py +++ b/pgcli/main.py @@ -22,8 +22,8 @@ except ImportError: setproctitle = None import sqlparse from prompt_toolkit import CommandLineInterface, Application, AbortAction -from prompt_toolkit.enums import DEFAULT_BUFFER -from prompt_toolkit.shortcuts import create_prompt_layout +from prompt_toolkit.enums import DEFAULT_BUFFER, EditingMode +from prompt_toolkit.shortcuts import create_prompt_layout, create_eventloop from prompt_toolkit.buffer import AcceptAction from prompt_toolkit.document import Document from prompt_toolkit.filters import Always, HasFocus, IsDone @@ -140,6 +140,7 @@ class PGCli(object): self._completer_lock = threading.Lock() self.register_special_commands() + self.eventloop = create_eventloop() self.cli = None def register_special_commands(self): @@ -338,7 +339,7 @@ class PGCli(object): try: while True: - document = self.cli.run() + document = self.cli.run(True) # The reason we check here instead of inside the pgexecute is # because we want to raise the Exit exception which will be @@ -468,6 +469,8 @@ class PGCli(object): complete_while_typing=Always(), accept_action=AcceptAction.RETURN_DOCUMENT) + editing_mode = EditingMode.VI if self.vi_mode else EditingMode.EMACS + application = Application( style=style_factory(self.syntax_style, self.cli_style), layout=layout, @@ -475,9 +478,11 @@ class PGCli(object): key_bindings_registry=key_binding_manager.registry, on_exit=AbortAction.RAISE_EXCEPTION, on_abort=AbortAction.RETRY, - ignore_case=True) + ignore_case=True, + editing_mode=editing_mode) - cli = CommandLineInterface(application=application) + cli = CommandLineInterface(application=application, + eventloop=self.eventloop) return cli @@ -15,7 +15,7 @@ install_requirements = [ 'pgspecial>=1.3.0', 'click >= 4.1', 'Pygments >= 2.0', # Pygments has to be Capitalcased. WTF? - 'prompt_toolkit==0.60', + 'prompt_toolkit>=1.0.0,<1.1.0', 'psycopg2 >= 2.5.4', 'sqlparse == 0.1.19', 'configobj >= 5.0.6', |