diff --git a/fill3/fill3/__init__.py b/fill3/fill3/__init__.py index 44bc657..3aaa981 100755 --- a/fill3/fill3/__init__.py +++ b/fill3/fill3/__init__.py @@ -409,9 +409,24 @@ class Fixed: ########################## +EXCEPTION = None _LAST_APPEARANCE = [] +def handle_exception(): + def decorating_func(func): + def wrapper(*args): + try: + return func(*args) + except Exception as exc: + global EXCEPTION + EXCEPTION = exc + SHUTDOWN_EVENT.set() + return wrapper + return decorating_func + + +@handle_exception() def draw_screen(widget): global _LAST_APPEARANCE appearance = widget.appearance(os.get_terminal_size()) @@ -419,6 +434,7 @@ def draw_screen(widget): _LAST_APPEARANCE = appearance +@handle_exception() def patch_screen(widget): global _LAST_APPEARANCE appearance = widget.appearance(os.get_terminal_size()) @@ -437,6 +453,7 @@ async def update_screen(screen_widget): APPEARANCE_CHANGED_EVENT.clear() +@handle_exception() def on_terminal_input(screen_widget): term_code = sys.stdin.read() if term_code.startswith(terminal.MOUSE): @@ -474,7 +491,8 @@ async def tui(title, screen_widget): loop.remove_reader(sys.stdin) finally: update_task.cancel() - + if EXCEPTION is not None: + raise EXCEPTION ########################## @@ -490,6 +508,8 @@ class _Screen: def on_keyboard_input(self, term_code): if term_code in ["q", terminal.ESC, terminal.CTRL_C]: SHUTDOWN_EVENT.set() + elif term_code == "e": + raise AssertionError # Program should shutdown and show exception. else: self.content = Filler(Text(repr(term_code))) APPEARANCE_CHANGED_EVENT.set()