do not suppress KeyboardInterrupts in CLI loader
This commit is contained in:
parent
18e0a8ecea
commit
332162775f
@ -24,6 +24,7 @@ class LoadingAnimation:
|
|||||||
self.ending_text = ending_text
|
self.ending_text = ending_text
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
self.done: bool = False
|
self.done: bool = False
|
||||||
|
self.keyboard_interrupt: bool = False
|
||||||
|
|
||||||
self._isatty = sys.stdout.isatty()
|
self._isatty = sys.stdout.isatty()
|
||||||
self._do_animation = bool(sys.stdout.isatty())
|
self._do_animation = bool(sys.stdout.isatty())
|
||||||
@ -53,16 +54,15 @@ class LoadingAnimation:
|
|||||||
exc_type: type[Exception],
|
exc_type: type[Exception],
|
||||||
exc_value,
|
exc_value,
|
||||||
tb,
|
tb,
|
||||||
) -> bool:
|
) -> None:
|
||||||
if exc_type is not None:
|
if exc_type is not None:
|
||||||
self.stop(interrupt=True)
|
self.stop(interrupt=True)
|
||||||
if exc_type is KeyboardInterrupt:
|
if exc_type is KeyboardInterrupt:
|
||||||
|
self.keyboard_interrupt = True
|
||||||
print("Operation cancelled by user. (KeyboardInterrupt)", flush=True)
|
print("Operation cancelled by user. (KeyboardInterrupt)", flush=True)
|
||||||
return True
|
return
|
||||||
return False
|
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
return False
|
|
||||||
|
|
||||||
def _animation(self) -> None:
|
def _animation(self) -> None:
|
||||||
for frame in cycle(self.frames):
|
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):
|
with LoadingAnimation(loading_txt, ending_text):
|
||||||
res = func(*args, **kwargs)
|
res = func(*args, **kwargs)
|
||||||
|
|
||||||
return res # type: ignore
|
return res
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user