-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanim.py
More file actions
30 lines (25 loc) · 699 Bytes
/
anim.py
File metadata and controls
30 lines (25 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python3
import threading
import sys
from time import sleep
class anim:
def __init__(self, frames):
self.frames = frames
self.running = False
def animate(self):
self.running = True
self.animation_thread = threading.Thread(target=self._run_animation)
self.animation_thread.start()
def _run_animation(self):
while self.running:
for frame in self.frames:
if not self.running:
break
sys.stdout.write(f"\r{frame} ")
sys.stdout.flush()
sleep(0.2)
def stop_animation(self):
self.running = False
self.animation_thread.join()
a = anim(["\\ Working...", "| Working...", "/ Working...", "- Working..."])
a.animate() ; sleep(3) ; a.stop_animation()