【问题标题】:readline set_completion_display_matches_hook requires return key before displaying promptreadline set_completion_display_matches_hook 在显示提示之前需要返回键
【发布时间】:2013-03-01 01:14:30
【问题描述】:

背景

您好,我正在尝试在 readline 中为我的选项卡完成输出编写自定义显示。这是我的display hook 函数-

代码

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

问题

但问题是我必须按回车键才能获得提示,这与默认的制表符完成输出不同,我可以立即获得提示。我看到 rl 模块已被另一个线程中的某人建议,但是没有办法通过 readline 本身完成它吗?

【问题讨论】:

    标签: python readline


    【解决方案1】:

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

    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 上为我工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多