fix help
[rainbowstream.git] / rainbowstream / interactive.py
index b7fabbcba728ec21b62c884fbfbdfed5c9b53595..546d776f554947dfcace97a8b7fc24e78ab84ba5 100644 (file)
@@ -1,5 +1,8 @@
 import readline
-import rlcompleter
+import os.path
+
+from .config import *
+
 
 class RainbowCompleter(object):
 
@@ -24,11 +27,13 @@ class RainbowCompleter(object):
             words = origline.split()
 
             if not words:
-                self.current_candidates = sorted(self.options.keys())
+                self.current_candidates = sorted([c for c in self.options])
             else:
                 try:
                     if begin == 0:
-                        candidates = self.options.keys()
+                        candidates = [c for c in self.options]
+                    elif words[-1] in self.options[words[0]]:
+                        candidates = []
                     else:
                         first = words[0]
                         candidates = self.options[first]
@@ -39,7 +44,7 @@ class RainbowCompleter(object):
                     else:
                         self.current_candidates = candidates
 
-                except (KeyError, IndexError), err:
+                except (KeyError, IndexError):
                     self.current_candidates = []
 
         try:
@@ -49,15 +54,40 @@ class RainbowCompleter(object):
         return response
 
 
+def get_history_items():
+    """
+    Get all history item
+    """
+    return [
+        readline.get_history_item(i)
+        for i in xrange(1, readline.get_current_history_length() + 1)
+    ]
+
+
+def read_history():
+    """
+    Read history file
+    """
+    if os.path.isfile(c['HISTORY_FILENAME']):
+        readline.read_history_file(c['HISTORY_FILENAME'])
+
+
+def save_history():
+    """
+    Save history to file
+    """
+    readline.write_history_file(c['HISTORY_FILENAME'])
+
+
 def init_interactive_shell(d):
     """
     Init the rainbow shell
     """
     readline.set_completer(RainbowCompleter(d).complete)
     readline.parse_and_bind('set editing-mode vi')
-    readline.parse_and_bind("set input-meta on")
-    readline.parse_and_bind("set convert-meta off")
-    readline.parse_and_bind("set output-meta on")
+    readline.parse_and_bind('set show-all-if-ambiguous on')
+    readline.parse_and_bind('set show-all-if-unmodified on')
+    readline.parse_and_bind('set skip-completed-text on')
     if 'libedit' in readline.__doc__:
         readline.parse_and_bind("bind ^I rl_complete")
     else: