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.25k stars 714 forks source link

Autosuggestion, add optimistic (no)update ? #252

Open Carreau opened 8 years ago

Carreau commented 8 years ago

I got a lag when the autosuggestion take times to build the list of suggestion, assuming vertically is time, and | is my cursor:

imp|ort
impo|
impo|rt
impo|
impor|t

You can easily reproduce that with :

from prompt_toolkit import prompt
from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory

class MyHist(InMemoryHistory):

    def __iter__(self):
        import time
        time.sleep(0.3)
        return super().__iter__()

history = MyHist()

while True:
    text = prompt('> ', history=history, auto_suggest=AutoSuggestFromHistory())
    print('You said: %s' % text)

My guess is that it should be possible to optimistically keep the previous suggestion if the new type letter is the same than the first one of the (previous) suggestions or something similar, or better, if current string is subset of current suggestion, keep it.

Thoughts?

jonathanslenders commented 8 years ago

I think this makes sense. I'll have a look later this week.

Carreau commented 8 years ago

No hurry, it seem also pretty easy for a newcomer to investigate the codebase. :-P