Skip to content

Commit 8a4f3a2

Browse files
committed
Implement LoadingAnimation class for console feedback
1 parent b461290 commit 8a4f3a2

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

clibot/animation.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import threading
22
import time
33
import sys
4+
from typing import List
45

56
# Loading animation
67
class LoadingAnimation:
8+
"""A class to display a loading animation in the console."""
9+
710
def __init__(self):
8-
self.symbols = ['⣾', '⣷', '⣯', '⣟', '⡿', '⢿', '⣻', '⣽']
9-
self.i = 0
10-
self.running = threading.Event()
11-
self.thread = None
11+
self.symbols: List[str] = ['⣾', '⣷', '⣯', '⣟', '⡿', '⢿', '⣻', '⣽']
12+
self.i: int = 0
13+
self.running: threading.Event = threading.Event()
14+
self.thread: threading.Thread = None
1215

13-
def loading_animation(self):
16+
def loading_animation(self) -> None:
17+
"""Display the loading animation."""
1418
while self.running.is_set():
1519
self.i = (self.i + 1) % len(self.symbols)
1620
if sys.stdout.isatty():
@@ -21,13 +25,15 @@ def loading_animation(self):
2125
if sys.stdout.isatty():
2226
print('\r\033[K', end='')
2327

24-
def start(self):
28+
def start(self) -> None:
29+
"""Start the loading animation."""
2530
if sys.stdout.isatty():
2631
self.running.set()
2732
self.thread = threading.Thread(target=self.loading_animation)
2833
self.thread.start()
2934

30-
def stop(self):
35+
def stop(self) -> None:
36+
"""Stop the loading animation."""
3137
self.running.clear()
3238
if self.thread is not None:
3339
self.thread.join()

0 commit comments

Comments
 (0)