Browse Source

Enable history in action language interactive prompt.

Joeri Exelmans 5 years ago
parent
commit
2c4aba04c2
1 changed files with 7 additions and 5 deletions
  1. 7 5
      src/sccd/action_lang/interactive/prompt.py

+ 7 - 5
src/sccd/action_lang/interactive/prompt.py

@@ -1,4 +1,5 @@
 import sys
+import readline
 from sccd.action_lang.dynamic.memory import *
 from sccd.action_lang.parser.text import *
 from lark.exceptions import *
@@ -7,13 +8,11 @@ if __name__ == "__main__":
   scope = Scope("interactive", parent=None)
   memory = Memory()
   memory.push_frame(scope)
+  readline.set_history_length(1000)
 
   while True:
-    sys.stdout.write("> ")
-    sys.stdout.flush()
-    line = sys.stdin.readline()
-
     try:
+      line = input("> ")
       stmt = parse_stmt(line)
       stmt.init_stmt(scope)
 
@@ -29,4 +28,7 @@ if __name__ == "__main__":
         stmt.exec(memory)
 
     except (LarkError, ModelError, SCCDRuntimeException) as e:
-      print(e)
+      print(e)
+    except KeyboardInterrupt:
+      print()
+      exit()