From: Axy Date: Sun, 29 Mar 2026 20:24:43 +0000 (+0200) Subject: Further error handling, almost done X-Git-Url: https://git.uwuaxy.net/animations_scrolling.mp4?a=commitdiff_plain;h=822fba37bf93e8082ab087041cc937c3f808f608;p=axy%2Fft%2Fa-maze-ing.git Further error handling, almost done --- 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()