Skip to content

Instantly share code, notes, and snippets.

@L3viathan
Last active January 8, 2024 08:46
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 L3viathan/ba7b177df2df392c877a2f240de74278 to your computer and use it in GitHub Desktop.
Save L3viathan/ba7b177df2df392c877a2f240de74278 to your computer and use it in GitHub Desktop.
Infinite progress indicator thing
import sys
from time import sleep
from contextlib import contextmanager
@contextmanager
def dots():
def _dots():
while True:
for i, char in enumerate("⠁⠃⠇⡇⣇⣧⣷⣿"):
if i:
yield f"\x08{char}"
else:
yield char
d = _dots()
def step():
print(next(d), end="", flush=True, file=sys.stderr)
try:
# hide cursor
print("\x1b[?25l", end="", flush=True, file=sys.stderr)
yield step
finally:
print("\x1b[?25h", flush=True, file=sys.stderr)
if __name__ == "__main__":
with dots() as dot:
for _ in range(48):
dot()
sleep(0.05)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment