File indexing completed on 2025-01-18 09:10:44
0001 import contextlib
0002 import sys
0003
0004 try:
0005 from halo import Halo
0006 except:
0007 Halo = None
0008
0009
0010 @contextlib.contextmanager
0011 def Spinner(text, persist=True, *args, **kwargs):
0012 stream = kwargs.get("stream", sys.stdout)
0013 if stream.isatty() and Halo is not None:
0014 spinner = Halo(text, *args, **kwargs)
0015 spinner.start()
0016 try:
0017 yield
0018 if persist:
0019 spinner.succeed()
0020 except:
0021 if persist:
0022 spinner.fail()
0023 raise
0024 finally:
0025 if not persist:
0026 spinner.stop()
0027 else:
0028 stream.write(text + "\n")
0029 yield