Quellcode durchsuchen

Added tab-completion support for queries

Stefan Schmidt vor 6 Jahren
Ursprung
Commit
e72a678e5f
1 geänderte Dateien mit 9 neuen und 0 gelöschten Zeilen
  1. 9 0
      code/ID2TLib/Controller.py

+ 9 - 0
code/ID2TLib/Controller.py

@@ -104,6 +104,15 @@ class Controller:
         Enters into the query mode. This is a read-eval-print-loop, where the user can input named queries or SQL
         queries and the results are printed.
         """
+
+        def make_completer(vocabulary):
+            def custom_template(text, state):
+                results = [x for x in vocabulary if x.startswith(text)] + [None]
+                return results[state]
+            return custom_template
+
+        readline.parse_and_bind('tab: complete')
+        readline.set_completer(make_completer(self.statisticsDB.get_all_named_query_keywords()+self.statisticsDB.get_all_sql_query_keywords()))
         print("Entering into query mode...")
         print("Enter statement ending by ';' and press ENTER to send query. Exit by sending an empty query..")
         buffer = ""