forked from ZedThree/zoidberg_progress
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzoidberg_progress.py
More file actions
executable file
·77 lines (64 loc) · 2.13 KB
/
zoidberg_progress.py
File metadata and controls
executable file
·77 lines (64 loc) · 2.13 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sys import stdout
from time import sleep
def zoidberg_progress(progress, barLength=40, ascii=False, pad=False, food='-', woop=False):
"""Displays or updates a console progress bar
Accepts a float between 0 and 1. Any int will be converted to a float.
A value under 0 represents a 'halt'.
A value at 1 or bigger represents 100%
Inputs
------
progress - Number between 0 and 1
barLength - Length of the progress bar [40]
ascii - Use '#' as the progress indicator, otherwise use a Unicode
character [False]
pad - Pad Zoidberg's claws to stop his head bobbing [False]
food - Symbol for Zoidberg to be chasing, should be length one string ['-']
woop - Zoidberg woops instead of inks [False]
"""
status = ""
if isinstance(progress, int):
progress = float(progress)
if not isinstance(progress, float):
progress = 0
status = "error: progress var must be float\r\n"
if progress < 0:
progress = 0
status = "Halt...\r\n"
if progress >= 1:
progress = 1
status = "Done...\r\n"
if barLength < 40:
barLength = 40
if ascii:
face = " (;,,,;) "
ink = "#"
else:
face = u" (°,,,°) "
ink = u"█"
open_claw = "(\/)"
closed_claw = "(|)"
if int(progress*barLength) % 2:
pad_ = pad * 0
left_claw = open_claw
right_claw = closed_claw
else:
pad_ = pad * 1
left_claw = ink*pad + closed_claw
right_claw = open_claw
zb = left_claw+face+right_claw
zb_middle = int(len(zb)/2)
start = int(round((barLength-zb_middle)*progress))
rest = barLength-start-zb_middle-pad_
if woop:
ink=("woop"*int(1+start/4))[:start]
text = u"\rProgress: [{start}{zb}{rest}] {perc:6.2f}% {stat}".format(
start=ink, zb=zb, perc=progress*100, rest=food*rest, stat=status)
stdout.write(text)
stdout.flush()
if __name__ == "__main__":
for ii in range(100):
zoidberg_progress(ii/99.0)
sleep(0.1)
print('')