From 332162775ff62848e8861572cbff1e40cdb16f3c Mon Sep 17 00:00:00 2001 From: foefl Date: Tue, 11 Nov 2025 09:53:28 +0100 Subject: [PATCH] do not suppress KeyboardInterrupts in CLI loader --- src/dopt_basics/cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dopt_basics/cli.py b/src/dopt_basics/cli.py index 6c4be60..3124b2e 100644 --- a/src/dopt_basics/cli.py +++ b/src/dopt_basics/cli.py @@ -24,6 +24,7 @@ class LoadingAnimation: self.ending_text = ending_text self.timeout = timeout self.done: bool = False + self.keyboard_interrupt: bool = False self._isatty = sys.stdout.isatty() self._do_animation = bool(sys.stdout.isatty()) @@ -53,16 +54,15 @@ class LoadingAnimation: exc_type: type[Exception], exc_value, tb, - ) -> bool: + ) -> None: if exc_type is not None: self.stop(interrupt=True) if exc_type is KeyboardInterrupt: + self.keyboard_interrupt = True print("Operation cancelled by user. (KeyboardInterrupt)", flush=True) - return True - return False + return self.stop() - return False def _animation(self) -> None: for frame in cycle(self.frames): @@ -100,6 +100,6 @@ def default_loading(func: Callable[P, T]) -> Callable[P, T]: with LoadingAnimation(loading_txt, ending_text): res = func(*args, **kwargs) - return res # type: ignore + return res return wrapper