Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

readline set_completion_display_matches_hook requires return key before displaying prompt

Background

Hi I am trying to write a custom display for my tab completion output in readline. Here is my display hook function-

Code

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

Question

But the problem is that I have to press the return key to get a prompt unlike the default tab completion output where I can get the prompt right away. I see rl module has been suggested by someone in another thread, but is there no way to get it done through readline itself?

like image 737
user2121826 Avatar asked Oct 27 '25 11:10

user2121826


1 Answers

Okay i found a way, not sure if this is the right way to fix it. But i printed the prompt and readline buffer at the end of the match_display_hook and all seems well and good. Here is my new 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()

This works well.

like image 138
user2121826 Avatar answered Oct 29 '25 07:10

user2121826