-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcSpinner.py
58 lines (49 loc) · 1.38 KB
/
cSpinner.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import sys
import threading
import time
class cSpinner(threading.Thread):
"""
Print information in the same line, giving feedback to the user
\details Prints a spinning text on the screen. Additional text may be attached as extra information. Extends the Thread class
"""
chars = ["\\","|","/","-"]
index = 0
keeprunning = True
paused = False;
msg = ""
def run(self):
"""
\brief Start the thread
"""
while self.keeprunning:
if (not self.paused): self.__printing(self.chars[self.index%len(self.chars)]+" "+self.msg)
time.sleep(0.1)
self.index +=1
self.__printing("")
def set_msg(self,text):
"""
\brief Set the extra message to print
\param text String to print
"""
self.msg = text;
def __printing(self,data):
"""
\brief print the information to stdout
"""
sys.stdout.write("\r\x1b[K"+data.__str__())
sys.stdout.flush()
def stop(self):
"""
\brief Stop the print thread.
"""
self.keeprunning = False
def pause(self):
"""
\brief Pause the print thread.
"""
self.paused = True;
def unpause(self):
"""
\brief continue the print thread.
"""
self.paused = False;