Mac not support screen
[rainbowstream.git] / rainbowstream / interactive.py
1 import readline
2 import rlcompleter
3
4 class RainbowCompleter(object):
5
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:
20 self.matches = [s
21 for s in self.options
22 if s and s.startswith(text)]
23 else:
24 self.matches = self.options
25
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)
38 readline.parse_and_bind('set editing-mode vi')
39 readline.parse_and_bind("set input-meta on")
40 readline.parse_and_bind("set convert-meta off")
41 readline.parse_and_bind("set output-meta on")
42 if 'libedit' in readline.__doc__:
43 readline.parse_and_bind("bind ^I rl_complete")
44 else:
45 readline.parse_and_bind("tab: complete")
46