From a0f381c9e80a86959b4af5e52807a8bcd1581d50 Mon Sep 17 00:00:00 2001 From: Paul Oliver Date: Thu, 29 Feb 2024 02:29:14 +0100 Subject: Added minimal mode. [#25] Toggle minimal mode with 'M' key. When on minimal mode, only current cycle, epoch and process count are shown. --- bin/README.md | 1 + bin/handler.py | 10 +++++++++- bin/printer.py | 23 +++++++++++++++++++++++ bin/salis.py | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/bin/README.md b/bin/README.md index 0d95d18..2ae4869 100644 --- a/bin/README.md +++ b/bin/README.md @@ -31,6 +31,7 @@ $ ./bin/salis.py load --file 16.sim |`fl` |Select first/last organism | |`k` |Scroll/go to selected (PROCESS and WORLD page) | |`X` |Toggle hex/decimal value printing | +|`M` |Toggle minimal mode | |Numbers `[1..0]` |Cycle simulation `2^((n-1) % 10)` steps | |Enter |Activate cursor (WORLD page) | diff --git a/bin/handler.py b/bin/handler.py index 2bc8c25..366b94a 100644 --- a/bin/handler.py +++ b/bin/handler.py @@ -32,6 +32,7 @@ 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.console_history = [] def process_cmd(self, cmd): @@ -39,7 +40,14 @@ class Handler: ncurses' getch() function, thus, they must be transformed into their character representations with 'ord()'. """ - if cmd == ord(" "): + # If in minimal mode, only listen to a subset of commands. + if self.__sim.minimal and cmd not in self.__min_commands: + return + + if cmd == ord("M"): + self.__printer.screen.clear() + self.__sim.minimal = not self.__sim.minimal + elif 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 dd3e9ca..fcdf73f 100644 --- a/bin/printer.py +++ b/bin/printer.py @@ -39,6 +39,7 @@ class Printer: # We can now initialize all other privates. self.__main = self.__get_main() self.__pages = self.__get_pages() + self.__minimal = self.__get_minimal() self.__main_scroll = 0 self.__proc_element_scroll = 0 self.__proc_gene_scroll = 0 @@ -381,6 +382,11 @@ class Printer: """ Print current page to screen. We use the previously generated '__pages' dictionary to easily associate a label to a Salis function. """ + # If in minimal mode, print only minial widget. + if self.__sim.minimal: + self.__print_minimal() + return + # Update selected proc data if in WORLD view. if self.current_page == "WORLD": self.__sim.lib.sal_proc_get_proc_data(self.selected_proc, cast( @@ -833,3 +839,20 @@ class Printer: ): self.selected_proc = proc_id break + + def __get_minimal(self): + """ Generate set of data fields to be printed on minimal mode. + """ + return [ + ("cycle", self.__sim.lib.sal_main_get_cycle), + ("epoch", self.__sim.lib.sal_main_get_epoch), + ("procs", self.__sim.lib.sal_proc_get_count), + ] + + def __print_minimal(self): + """ Print minimal mode data fields. + """ + self.__print_line(1, "Salis --- Minimal mode") + + for i, field in enumerate(self.__minimal): + self.__print_line(i + 2, "{}: {}".format(field[0], field[1]())) diff --git a/bin/salis.py b/bin/salis.py index 31a6ac1..8c477ff 100755 --- a/bin/salis.py +++ b/bin/salis.py @@ -53,6 +53,7 @@ class Salis: self.printer = Printer(self) self.handler = Handler(self) self.state = "paused" + self.minimal = False # Based on CLI arguments, initialize a new Salis simulation or load # existing one from file. -- cgit v1.2.1