Skip to content

Instantly share code, notes, and snippets.

@bblanchon
Created November 23, 2021 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bblanchon/b6387161b019bb905d2a2dedc9a59c65 to your computer and use it in GitHub Desktop.
Save bblanchon/b6387161b019bb905d2a2dedc9a59c65 to your computer and use it in GitHub Desktop.
Nestable Halo spinners
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!")
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