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.37k stars 716 forks source link

"end" completion if unique #595

Open neonrust opened 6 years ago

neonrust commented 6 years ago

How can I achieve this behavior? Probably this only applies for complete_while_typing=True.

Usually, while the completion is not unique, the list of completions is shown. If I type something more that list is updated to show the now-matching completions.

This is all great. :)

However, if what I've typed (so far) only has a single completion (i.e. it's unique) - and I press TAB - I want that completion to be filled in and the completion list to go away.

I can't seem to find any "end completion" function, or something like that...?

Additionally I'd like a to a space after the completion to be inserted, but that's a grammar-specific thing. Similar to a shell when completing a unique file name. Thus, pressing TAB directly afterwards it would show completions for the next grammatical item (whatever that may be).

I'm using 2.0, bleeding edge :)

asmeurer commented 6 years ago

I don't know about 2.0, but this is already how completions work for me, at least for complete_while_typing=False.

For the space, I think you just need to add a space to the end of the item in the completion list, so that it gets inserted along with the rest of the text.

neonrust commented 6 years ago

Yes, but it seems the trick here is to achieve this behavior also for complete_while_typing=True.

With it set to False the completion list is hidden for each typed key anyway, so when enough is typed for it to be unique there isn't a completion list to begin with. And it's then also not shown when pressing TAB.

All the PT examples I've tried (with it set to True) has the same behavior (thankfully); for completion to end, a space (or something) must be inserted, just pressing TAB cycles between the one completion and no completion, with the completion list shown.