def main_completer_handler(self, text, state):
""" Handler of all input entries, tabs, and history
:param text: input text
:type text: string.
:param state: current state
:type state: string.
"""
response = None
# Build match list on first iteration else continue
if state == 0:
origline = readline.get_line_buffer()
begin = readline.get_begidx()
end = readline.get_endidx()
being_completed = origline[begin:end]
words = origline.split()
if not words:
# option for words list
self.current_candidates = sorted(self.options.keys())
else:
# traverse all words entries and passing accordingly
try:
if begin == 0:
# first word
candidates = self.options.keys()
else:
# later word
first = words[0]
candidates = self.options[first]
if being_completed:
# match options with portion of input being completed
self.current_candidates = [w for w in candidates\
if w.lower().startswith(being_completed.lower())]
else:
# matching empty string so use all candidates
self.current_candidates = candidates
except (KeyError, IndexError):
self.current_candidates = []
# Return the state from the match list if found otherwise return None.
try:
response = self.current_candidates[state]
except IndexError:
# No candidate found for state
response = None
# Response return
return response
评论列表
文章目录