]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricatasc: add readline completion
authorEric Leblond <eric@regit.org>
Fri, 30 Nov 2012 17:24:00 +0000 (18:24 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 26 Feb 2013 11:32:47 +0000 (12:32 +0100)
scripts/suricatasc/suricatasc.in

index 00fd5cb0d7683592182e50b3e6f7ef1c9cfe30ea..494ab1d2cdbadb440d1c928cdc027723256a4e59 100755 (executable)
@@ -21,6 +21,24 @@ from socket import socket, AF_UNIX, error
 from time import sleep
 import sys
 
+class Completer:
+    def __init__(self, words):
+        self.words = words
+        self.generator = None
+
+    def complete(self, text):
+        for word in self.words:
+            if word.startswith(text):
+                yield word
+
+    def __call__(self, text, state):
+        if state == 0:
+            self.generator = self.complete(text)
+        try:
+            return self.generator.next()
+        except StopIteration:
+            return None
+        return None
 
 def json_recv(socket):
     cmdret = None
@@ -81,6 +99,8 @@ cmd_list.append("quit")
 
 # if ok loop
 try:
+    readline.set_completer(Completer(cmd_list))
+    readline.set_completer_delims(";")
     readline.parse_and_bind('tab: complete')
     while True:
         command = raw_input(">>> ").strip()