Created
November 23, 2021 08:23
-
-
Save bblanchon/b6387161b019bb905d2a2dedc9a59c65 to your computer and use it in GitHub Desktop.
Nestable Halo spinners
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from halo_nestable import HaloNestable | |
import time | |
with HaloNestable("Top level") as spinner: | |
time.sleep(2) | |
with HaloNestable("Nested"): | |
time.sleep(2) | |
time.sleep(2) | |
spinner.succeed("Great success!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from halo import Halo | |
_stack = [] | |
class HaloNestable: | |
def __init__(self, *args, **kwargs): | |
self.halo = Halo(*args, **kwargs) | |
def __getattr__(self, attr): | |
return getattr(self.halo, attr) | |
def __enter__(self): | |
if _stack: | |
_stack[-1].stop() | |
_stack.append(self.halo) | |
return self.halo.start() | |
def __exit__(self, type, value, traceback): | |
self.halo.stop() | |
_stack.pop() | |
if _stack: | |
_stack[-1].start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment