-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
55 lines (46 loc) · 1.76 KB
/
__init__.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
import sys
import math
class jhpbar:
def __init__(self, steps, size=20, prefix='', postfix='', color=0):
self.size = size
self.steps = steps
self.update_step = self.steps / self.size
self.count = 0
self.progress_bar_origin = '-' * size
self.progress_bar = self.progress_bar_origin
self.progress = 1
self.prefix = prefix
self.postfix = postfix
self.result = self.prefix + ' ' + self.progress_bar + ' ' + self.postfix
self.font_color_end = '\033[0m'
self.font_color = ''
if color == 0:
self.font_color = ''
elif color == 1: # red
self.font_color = '\033[31m'
elif color == 2: # green
self.font_color = '\033[32m'
elif color == 3: # blue
self.font_color = '\033[34m'
def update(self, count=1, prefix='', postfix=''):
self.count += count
if prefix != '':
self.prefix = prefix
if postfix != '':
self.postfix = postfix
self.progress = math.ceil(self.count / self.update_step)
self.progress_bar = self.progress_bar_origin.replace('-', '▉', self.progress)
self.result = f'{self.font_color}{self.prefix} {self.progress_bar} {self.postfix}{self.font_color_end}'
sys.stdout.write('\r' + self.result)
sys.stdout.flush()
if self.count == self.steps:
print()
def reset(self, progress=1, prefix='', postfix=''):
self.progress = progress
self.count = 0
self.progress_bar = '-' * self.size
if prefix != '':
self.prefix = prefix
if postfix != '':
self.postfix = postfix
self.result = self.prefix + ' ' + self.progress_bar + ' ' + self.postfix