4 class RainbowCompleter(object):
6 def __init__(self
, options
):
10 self
.options
= options
11 self
.current_candidates
= []
14 def complete(self
, text
, state
):
20 origline
= readline
.get_line_buffer()
21 begin
= readline
.get_begidx()
22 end
= readline
.get_endidx()
23 being_completed
= origline
[begin
:end
]
24 words
= origline
.split()
27 self
.current_candidates
= sorted(self
.options
.keys())
31 candidates
= self
.options
.keys()
34 candidates
= self
.options
[first
]
37 self
.current_candidates
= [ w
for w
in candidates
38 if w
.startswith(being_completed
) ]
40 self
.current_candidates
= candidates
42 except (KeyError, IndexError), err
:
43 self
.current_candidates
= []
46 response
= self
.current_candidates
[state
]
52 def init_interactive_shell(d
):
54 Init the rainbow shell
56 readline
.set_completer(RainbowCompleter(d
).complete
)
57 readline
.parse_and_bind('set editing-mode vi')
58 readline
.parse_and_bind("set input-meta on")
59 readline
.parse_and_bind("set convert-meta off")
60 readline
.parse_and_bind("set output-meta on")
61 if 'libedit' in readline
.__doc
__:
62 readline
.parse_and_bind("bind ^I rl_complete")
64 readline
.parse_and_bind("tab: complete")