Using the library readline
I managed to provide tab completion when using input()
. My code until now looks like this:
import readline
class TabComplete:
def __init__(self, wordList):
self.wordList = wordList
def complete(self,text,state):
results = [x for x in self.wordList if x.startswith(text)] + [None]
return results[state]
readline.parse_and_bind("tab: complete")
tabComplete = ["IF", "IF_ELSE", "FOR", "WHILE"]
completer = TabComplete(tabComplete)
readline.set_completer(completer.complete)
userTyped = input("prompt > ")
If I start typing I
and then hit twice on tab
it will propose me IF
and IF_ELSE
as expected.
What I am searching now is:
- if I start typing
i
and then hit twicetab
is there a way to still make it proposeIF
andIF_ELSE
? - if I type
IF EL
can I tell him on real time to replace the space by_
so the completion works?