forked from awade/netgpibdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
termstatus.py
executable file
·50 lines (42 loc) · 1.28 KB
/
termstatus.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
from __future__ import division
import sys
class statusTxt:
def __init__(self,initTxt):
self.txtlen = len(initTxt)
self.txt = initTxt
print(initTxt)
sys.stdout.flush()
def update(self, updateTxt):
print ("\010"+"\010"*self.txtlen+updateTxt)
sys.stdout.flush()
self.txtlen = len(updateTxt)
self.txt = updateTxt
def end(self,updateTxt=""):
if updateTxt == "":
print("")
else:
print ("\010"+"\010"*self.txtlen+updateTxt)
sys.stdout.flush()
class progressBar:
def __init__(self, width, nTot):
self.width=width
self.nTot=nTot
self.stepped=0
sys.stdout.write('['+' '*width+']')
sys.stdout.write('\r'*(width+2))
sys.stdout.flush()
self.done=False
def update(self, val):
steps = int(round(val/self.nTot*self.width))
if steps > self.stepped:
for ii in range(steps-self.stepped):
sys.stdout.write('\r'+'*')
sys.stdout.flush()
self.stepped=steps
if val == self.nTot:
self.end()
def end(self):
if self.done is False:
sys.stdout.write('\b] Done!')
sys.stdout.flush()
self.done=True