diff options
author | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 02:29:14 +0100 |
---|---|---|
committer | Paul Oliver <contact@pauloliver.dev> | 2024-02-29 02:29:14 +0100 |
commit | 8bef0b04edd10fe15589ae97edee5af177c635e0 (patch) | |
tree | 5e9d353bffd0d804f0108376519676f5d6419808 | |
parent | 64e850217ad57714856617c82e48994da6989535 (diff) |
Escape key now saves and exits.
[#25] I've returned the Escape key functionality as it is needed to
exit the simulator when in minimal mode.
-rw-r--r-- | bin/README.md | 1 | ||||
-rw-r--r-- | bin/handler.py | 16 |
2 files changed, 15 insertions, 2 deletions
diff --git a/bin/README.md b/bin/README.md index 2ae4869..7340b8e 100644 --- a/bin/README.md +++ b/bin/README.md @@ -34,6 +34,7 @@ $ ./bin/salis.py load --file 16.sim |`M` |Toggle minimal mode | |Numbers `[1..0]` |Cycle simulation `2^((n-1) % 10)` steps | |Enter |Activate cursor (WORLD page) | +|Escape |Save and quit simulation | ### Console commands The console opens up when `c` is pressed. Commands, with their respective 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(" "): |