aboutsummaryrefslogtreecommitdiff
path: root/bin/handler.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/handler.py')
-rw-r--r--bin/handler.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/bin/handler.py b/bin/handler.py
index 366b94a..40fafea 100644
--- a/bin/handler.py
+++ b/bin/handler.py
@@ -25,6 +25,8 @@ import curses
class Handler:
+ KEY_ESCAPE = 27
+
def __init__(self, sim):
""" Handler constructor. Simply link this class to the main simulation
class and printer class and create symbol dictionary.
@@ -32,9 +34,17 @@ class Handler:
self.__sim = sim
self.__printer = sim.printer
self.__inst_dict = self.__get_inst_dict()
- self.__min_commands = [ord("M"), ord(" "), curses.KEY_RESIZE]
+ self.__min_commands = [
+ ord("M"),
+ ord(" "),
+ curses.KEY_RESIZE,
+ self.KEY_ESCAPE,
+ ]
self.console_history = []
+ # Set short delay for ESCAPE key (which is used to exit the simulator).
+ os.environ.setdefault("ESCDELAY", "25")
+
def process_cmd(self, cmd):
""" Process incoming commands from curses. Commands are received via
ncurses' getch() function, thus, they must be transformed into their
@@ -44,7 +54,9 @@ class Handler:
if self.__sim.minimal and cmd not in self.__min_commands:
return
- if cmd == ord("M"):
+ if cmd == self.KEY_ESCAPE:
+ self.__on_quit([None], save=True)
+ elif cmd == ord("M"):
self.__printer.screen.clear()
self.__sim.minimal = not self.__sim.minimal
elif cmd == ord(" "):