Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 97e3d9e

Browse files
authored
Merge pull request #13475 from asteppke/master
Allow autosuggestions to be configurable.
2 parents 5fd6e5a + 000929a commit 97e3d9e

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

IPython/terminal/interactiveshell.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,29 @@ def _displayhook_class_default(self):
317317
help="Allows to enable/disable the prompt toolkit history search"
318318
).tag(config=True)
319319

320+
autosuggestions_provider = Unicode(
321+
"AutoSuggestFromHistory",
322+
help="Specifies from which source automatic suggestions are provided. "
323+
"Can be set to `'AutoSuggestFromHistory`' or `None` to disable"
324+
"automatic suggestions. Default is `'AutoSuggestFromHistory`'.",
325+
allow_none=True,
326+
).tag(config=True)
327+
328+
def _set_autosuggestions(self, provider):
329+
if provider is None:
330+
self.auto_suggest = None
331+
elif provider == "AutoSuggestFromHistory":
332+
self.auto_suggest = AutoSuggestFromHistory()
333+
else:
334+
raise ValueError("No valid provider.")
335+
if self.pt_app:
336+
self.pt_app.auto_suggest = self.auto_suggest
337+
338+
@observe("autosuggestions_provider")
339+
def _autosuggestions_provider_changed(self, change):
340+
provider = change.new
341+
self._set_autosuggestions(provider)
342+
320343
prompt_includes_vi_mode = Bool(True,
321344
help="Display the current vi mode (when using vi editing mode)."
322345
).tag(config=True)
@@ -374,7 +397,7 @@ def prompt():
374397

375398
self.pt_loop = asyncio.new_event_loop()
376399
self.pt_app = PromptSession(
377-
auto_suggest=AutoSuggestFromHistory(),
400+
auto_suggest=self.auto_suggest,
378401
editing_mode=editing_mode,
379402
key_bindings=key_bindings,
380403
history=history,
@@ -576,6 +599,7 @@ def init_alias(self):
576599

577600
def __init__(self, *args, **kwargs):
578601
super(TerminalInteractiveShell, self).__init__(*args, **kwargs)
602+
self._set_autosuggestions(self.autosuggestions_provider)
579603
self.init_prompt_toolkit_cli()
580604
self.init_term_title()
581605
self.keep_running = True

0 commit comments

Comments
 (0)