prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.13k stars 716 forks source link

READLINE_LIKE completer not completing #1375

Open rinxor opened 3 years ago

rinxor commented 3 years ago

Using a READLINE_LIKE completer doesn't function as expected. When there is a common prefix it will fill it in (e.g. '<' in the example code) but it will not tab complete any further than that or display suggestions when typing more than '<'.

Another minor bug with READLINE_LIKE completer is using a bottom toolbar is redisplaying it above the readline completions every time you press tab.

#!/usr/bin/env python

from prompt_toolkit.completion import WordCompleter
from prompt_toolkit.shortcuts import CompleteStyle, prompt

test_completer = WordCompleter(['<html>', '<body>', '<head>', '<title>'])

prompt_params = {}
prompt_params['completer'] = test_completer
prompt_params['complete_style'] = CompleteStyle.READLINE_LIKE
prompt_params['bottom_toolbar'] = "should only appear at the bottom"

while True:
    prompt(**prompt_params)
jiasli commented 10 months ago

I am able to reproduce. Launch @rinxor's script and press Tab twice. It will re-display the bottom_toolbar above the readline completions.

Then press h and Tab, no candidates will be show:

image

Not only the READLINE_LIKE completer has such problem. The default CompleteStyle.COLUMN can't show candidates after typing <h either.

Running this script provided in official doc https://python-prompt-toolkit.readthedocs.io/en/stable/pages/asking_for_input.html#autocompletion

from prompt_toolkit import prompt
from prompt_toolkit.completion import WordCompleter

html_completer = WordCompleter(['<html>', '<body>', '<head>', '<title>'])
text = prompt('Enter HTML: ', completer=html_completer)
print('You said: %s' % text)

image

image