Python readline设置\完成\显示\匹配\钩子需要返回键才能显示提示

Python readline设置\完成\显示\匹配\钩子需要返回键才能显示提示,python,readline,Python,Readline,背景 您好,我正试图在readline中为我的制表符完成输出编写一个自定义显示。这是我的显示挂钩功能- 代码 def match_display_hook(self, substitution, matches, longest_match_length): print '' for match in matches: print match readline.redisplay() 问题 但问题是,我必须按return键才能得到提示,这与默认的tab

背景

您好,我正试图在readline中为我的制表符完成输出编写一个自定义显示。这是我的
显示挂钩
功能-

代码

def match_display_hook(self, substitution, matches, longest_match_length):
    print ''
    for match in matches:
        print match
    readline.redisplay()
问题


但问题是,我必须按return键才能得到提示,这与默认的tab completion输出不同,我可以立即得到提示。我看到另一个线程中有人建议使用
rl
模块,但是没有办法通过readline本身完成吗?

好的,我找到了一种方法,不确定这是否是修复它的正确方法。但是我在match_display_hook的末尾打印了提示符和readline缓冲区,看起来一切都很好。这是我的新火柴展示钩:

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()

这很有效。

在OSX 10.9.5上对我很有效