我正在尝试编写一个函数来在用户按下Tab键时显示自定义视图。显然,“ set_completion_display_matches_hook”功能是我所需要的,我可以显示一个自定义视图,但问题是我必须按Enter才能再次获得提示。
Python2中的解决方案似乎就是这样(此处的解决方案):
def match_display_hook(self, substitution, matches, longest_match_length):
print ''
for match in matches:
print match
print self.prompt.rstrip(),
print readline.get_line_buffer(),
readline.redisplay()
但这不适用于Python3。我进行了以下语法更改:
def match_display_hook(self, substitution, matches, longest_match_length):
print('\n----------------------------------------------\n')
for match in matches:
print(match)
print(self.prompt.rstrip() + readline.get_line_buffer())
readline.redisplay()
有什么想法吗?
沧海一幻觉
Cats萌萌
相关分类