Roundup Tracker - Issues

Message7962

Author rouilj
Recipients rouilj
Date 2024-03-13.22:29:24
Message-id <1710368964.28.0.109447302231.issue2551326@roundup.psfhosted.org>
In-reply-to
More reference:

https://eli.thegreenplace.net/2016/basics-of-using-the-readline-library/

with example:

import readline

def make_completer(vocabulary):
    def custom_complete(text, state):
        # None is returned for the end of the completion session.
        results = [x for x in vocabulary if x.startswith(text)] + [None]
        # A space is added to the completion since the Python readline doesn't
        # do this on its own. When a word is fully completed we want to mimic
        # the default readline library behavior of adding a space after it.
        return results[state] + " "
    return custom_complete

def main():
    vocabulary = {'cat', 'dog', 'canary', 'cow', 'hamster'}
    readline.parse_and_bind('tab: complete')
    readline.set_completer(make_completer(vocabulary))

    try:
        while True:
            s = input('>> ').strip()
            print('[{0}]'.format(s))
    except (EOFError, KeyboardInterrupt) as e:
        print('\nShutting down...')

if __name__ == '__main__':
    main()
History
Date User Action Args
2024-03-13 22:29:24rouiljsetmessageid: <1710368964.28.0.109447302231.issue2551326@roundup.psfhosted.org>
2024-03-13 22:29:24rouiljsetrecipients: + rouilj
2024-03-13 22:29:24rouiljlinkissue2551326 messages
2024-03-13 22:29:24rouiljcreate