Python Prompt Toolkit: How to always open/show autocompleter?

1k views Asked by At

I use prompt_toolkit to ask the user for some input:

from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter

prompt('Input: ', completer=WordCompleter(['abc', 'def', 'xyz']))

Is it possible to show the suggestions automatically without any user intervention (no tab key)?

example

1

There are 1 answers

0
Louie Lu On

You can use pre_run hook to prompt it.

from prompt_toolkit.application.current import get_app

def prompt_autocomplete():
    app = get_app()
    b = app.current_buffer
    if b.complete_state:
        b.complete_next()
    else:
        b.start_completion(select_first=False)

prompt(pre_run=prompt_autocomplete)