Skip to content

Commit 7f9abf0

Browse files
authored
Update _animate to support non-indexable iterators (#45)
1 parent 2864f2d commit 7f9abf0

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

rigging/interact.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
import asyncio
4-
import sys
4+
import itertools
55
import typing as t
66

77
from colorama import Fore, Style
@@ -14,13 +14,10 @@
1414

1515

1616
async def _animate(*, delay: float = 0.5, chars: list[str] | None = None, color: str = Fore.BLUE) -> None:
17-
chars = chars or [" ", ". ", ".. ", "..."]
18-
i = 0
17+
chars = itertools.cycle(chars or [" ", ". ", ".. ", "..."])
1918
while True:
20-
print(f"{color}{chars[i]}{Style.RESET_ALL}", end="\r")
21-
sys.stdout.flush()
19+
print(f"{color}{next(chars)}{Style.RESET_ALL}", end="\r", flush=True)
2220
await asyncio.sleep(delay)
23-
i = (i + 1) % len(chars)
2421

2522

2623
async def interact(

0 commit comments

Comments
 (0)