diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 7a207eb..302d81f 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -317,11 +317,33 @@ class TerminalInteractiveShell(InteractiveShell): help="Allows to enable/disable the prompt toolkit history search" ).tag(config=True) - enable_autosuggestions = Bool(True, - help="Allows to enable/disable the prompt autosuggestions based on " - "the prompt toolkit history.", + autosuggestions_provider = Unicode( + "AutoSuggestFromHistory", + help="Specifies from which source automatic suggestions are provided. " + "Can be set to `'AutoSuggestFromHistory`' or `None` to disable" + "automatic suggestions. Default is `'AutoSuggestFromHistory`'.", + allow_none=True, ).tag(config=True) + prompt_includes_vi_mode = Bool( + True, help="Display the current vi mode (when using vi editing mode)." + ).tag(config=True) + + def _set_autosuggestions(self, provider): + if provider is None: + self.auto_suggest = None + elif provider == "AutoSuggestFromHistory": + self.auto_suggest = AutoSuggestFromHistory() + else: + raise ValueError("No valid provider.") + if self.pt_app: + self.pt_app.auto_suggest = self.auto_suggest + + @observe("autosuggestions_provider") + def _autosuggestions_provider_changed(self, change): + provider = change.new + self._set_autosuggestions(provider) + prompt_includes_vi_mode = Bool(True, help="Display the current vi mode (when using vi editing mode)." ).tag(config=True) @@ -375,16 +397,11 @@ class TerminalInteractiveShell(InteractiveShell): self._style = self._make_style_from_name_or_cls(self.highlighting_style) self.style = DynamicStyle(lambda: self._style) - if self.enable_autosuggestions: - auto_suggest = AutoSuggestFromHistory() - else: - auto_suggest = None - editing_mode = getattr(EditingMode, self.editing_mode.upper()) self.pt_loop = asyncio.new_event_loop() self.pt_app = PromptSession( - auto_suggest=auto_suggest, + auto_suggest=self.auto_suggest, editing_mode=editing_mode, key_bindings=key_bindings, history=history, @@ -586,6 +603,7 @@ class TerminalInteractiveShell(InteractiveShell): def __init__(self, *args, **kwargs): super(TerminalInteractiveShell, self).__init__(*args, **kwargs) + self._set_autosuggestions(self.autosuggestions_provider) self.init_prompt_toolkit_cli() self.init_term_title() self.keep_running = True