From 822fba37bf93e8082ab087041cc937c3f808f608 Mon Sep 17 00:00:00 2001 From: Axy Date: Sun, 29 Mar 2026 22:24:43 +0200 Subject: [PATCH] Further error handling, almost done --- a_maze_ing.py | 10 ++++++++-- mazegen/display/observer.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/a_maze_ing.py b/a_maze_ing.py index d837464..a5ef646 100644 --- a/a_maze_ing.py +++ b/a_maze_ing.py @@ -1,4 +1,5 @@ from sys import stderr +import time from typing import Never from mazegen.config.parser_combinator import ParseError from mazegen.display.observer import MazeRegenerate, TTYTracker @@ -75,8 +76,13 @@ if config.visual: maze_main() - with open(config.output_file, "w") as f: - f.write(format_output(maze)) + try: + with open(config.output_file, "w") as f: + f.write(format_output(maze)) + except IOError: + if tty_tracker is not None: + tty_tracker.uninit() + error(f"Failed to write to file {config.output_file}\n") while tty_tracker is not None: tty_tracker.display_maze(wait_for_tick=True) diff --git a/mazegen/display/observer.py b/mazegen/display/observer.py index 79e1b76..d8c0a1d 100644 --- a/mazegen/display/observer.py +++ b/mazegen/display/observer.py @@ -182,3 +182,9 @@ class TTYTracker: self.__dirty_tracker.clear() self.poll_events() self.__backend.present() + + def uninit(self) -> None: + """ + Uninitializes the backed + """ + self.__backend.uninit() -- 2.53.0