From bb9e0f1631dd0773ba24d023b57cafba4b283a74 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Thu, 29 Feb 2024 02:29:14 +0100 Subject: ESCAPE key no longer quits simulation. [#19] I felt it was too easy to quit the simulation accidentally. Now, a user has to type 'q' or 'quit' on the console in order to exit. --- bin/README.md | 1 - bin/handler.py | 9 +-------- bin/printer.py | 6 ++++-- 3 files changed, 5 insertions(+), 11 deletions(-) (limited to 'bin') diff --git a/bin/README.md b/bin/README.md index 6bb42a5..0a714b7 100644 --- a/bin/README.md +++ b/bin/README.md @@ -32,7 +32,6 @@ $ ./bin/salis.py load --file 16.sim |`X` |Toggle hex/decimal value printing | |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 9305d14..7bde479 100644 --- a/bin/handler.py +++ b/bin/handler.py @@ -25,8 +25,6 @@ import curses class Handler: - ESCAPE_KEY = 27 - def __init__(self, sim): """ Handler constructor. Simply link this class to the main simulation class and printer class and create symbol dictionary. @@ -41,12 +39,7 @@ class Handler: ncurses' getch() function, thus, they must be transformed into their character representations with 'ord()'. """ - if cmd == self.ESCAPE_KEY: - self.__sim.lib.sal_main_save( - self.__sim.save_file_path.encode("utf-8") - ) - self.__sim.exit() - elif cmd == ord(" "): + if cmd == ord(" "): self.__sim.toggle_state() elif cmd == curses.KEY_LEFT: self.__printer.flip_page(-1) diff --git a/bin/printer.py b/bin/printer.py index 67794ea..9997a0c 100644 --- a/bin/printer.py +++ b/bin/printer.py @@ -20,6 +20,8 @@ from world import World class Printer: + ESCAPE_KEY = 27 + def __init__(self, sim): """ Printer constructor. It takes care of starting up curses, defining the data pages and setting the printer on its initial state. @@ -248,7 +250,7 @@ class Printer: self.screen.move(self.__curs_y, self.__curs_x) cmd = self.screen.getch() - if cmd in [ord("c"), curses.KEY_RESIZE, Handler.ESCAPE_KEY]: + if cmd in [ord("c"), curses.KEY_RESIZE, self.ESCAPE_KEY]: self.on_resize() break elif cmd == curses.KEY_LEFT: @@ -305,7 +307,7 @@ class Printer: def validator(cmd): EXIT = 7 - if cmd in [curses.KEY_RESIZE, Handler.ESCAPE_KEY]: + if cmd in [curses.KEY_RESIZE, self.ESCAPE_KEY]: console.clear() return EXIT elif cmd == curses.KEY_UP: -- cgit v1.2.1