简体   繁体   中英

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

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)?

例子

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM