Commit | Line | Data |
---|---|---|
94a5f62e | 1 | import readline |
4ac5fe72 | 2 | import rlcompleter |
b2b933a9 | 3 | |
94a5f62e | 4 | class RainbowCompleter(object): |
b2b933a9 | 5 | |
94a5f62e | 6 | def __init__(self, options): |
7 | """ | |
8 | Init | |
9 | """ | |
10 | self.options = sorted(options) | |
11 | return | |
12 | ||
13 | def complete(self, text, state): | |
14 | """ | |
15 | Complete | |
16 | """ | |
17 | response = None | |
18 | if state == 0: | |
19 | if text: | |
b2b933a9 | 20 | self.matches = [s |
94a5f62e | 21 | for s in self.options |
22 | if s and s.startswith(text)] | |
23 | else: | |
24 | self.matches = self.options[:] | |
b2b933a9 | 25 | |
94a5f62e | 26 | try: |
27 | response = self.matches[state] | |
28 | except IndexError: | |
29 | response = None | |
30 | return response | |
31 | ||
32 | ||
33 | def init_interactive_shell(set): | |
34 | """ | |
35 | Init the rainbow shell | |
36 | """ | |
37 | readline.set_completer(RainbowCompleter(set).complete) | |
94a5f62e | 38 | readline.parse_and_bind('set editing-mode vi') |
4ac5fe72 O |
39 | if 'libedit' in readline.__doc__: |
40 | readline.parse_and_bind("bind ^I rl_complete") | |
41 | else: | |
42 | readline.parse_and_bind("tab: complete") |