我正在使用以下代码来完成文本:
class MyCompleter(object): # Custom completer
def __init__(self, options):
self.options = sorted(options)
def complete(self, text, state):
if state == 0: # on first trigger, build possible matches
if text: # cache matches (entries that start with entered text)
self.matches = [s for s in self.options
if s and s.startswith(text)]
else: # no text entered, all matches possible
self.matches = self.options[:]
# return match indexed by state
try:
return self.matches[state]
except IndexError:
return None
def setCompleter(listOfItems):
readline.parse_and_bind('tab: complete')
readline.parse_and_bind('set editing-mode vi')
completer = MyCompleter(listOfItems)
readline.set_completer(completer.complete)
选项取自数据库。当我需要完成时,它不提供选项,而不是包含带有变音符号的国际字符。我可以自定义代码以提供包含变音符号的选项吗?