From: Eric Leblond Date: Fri, 30 Nov 2012 17:24:00 +0000 (+0100) Subject: suricatasc: add readline completion X-Git-Tag: suricata-1.4.1~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bb639e4a6d28860d5489f53cf82bcbb660abe2ef;p=thirdparty%2Fsuricata.git suricatasc: add readline completion --- diff --git a/scripts/suricatasc/suricatasc.in b/scripts/suricatasc/suricatasc.in index 00fd5cb0d7..494ab1d2cd 100755 --- a/scripts/suricatasc/suricatasc.in +++ b/scripts/suricatasc/suricatasc.in @@ -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()