Last active
January 8, 2024 08:46
-
-
Save L3viathan/ba7b177df2df392c877a2f240de74278 to your computer and use it in GitHub Desktop.
Infinite progress indicator thing
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
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