-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
51 lines (40 loc) · 1.27 KB
/
test.py
File metadata and controls
51 lines (40 loc) · 1.27 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
import time
from handler.output import OutputBoard
class ProgressRenderer:
def __init__(self, start: int, end: int = None, step: int = 1):
if end is None:
end = start
start = 0
self.start = start
self.end = end
self.step = step
class Progress:
def __init__(self, start: int, end: int = None, step: int = 1):
if end is None:
end = start
start = 0
self.start = start
self.end = end
self.step = step
def bar(self, cur: int, width: int = 10):
if cur < self.start:
cur = self.start
elif cur > self.end:
cur = self.end
bar = int((cur - self.start) / (self.end - self.start) * width)
return f"[{'=' * bar}{' ' * (width - bar)}]"
def __iter__(self):
for i in range(self.start, self.end, self.step):
yield i
def __len__(self):
return (self.end - self.start) // self.step
def __next__(self):
return next(self)
if __name__ == '__main__':
board = OutputBoard()
board.add_unit('test', 3, True)
board.set_title('test', 'test title')
board.set_head('test', 'test head')
for i in range(1000):
board.append('test', f"line {i}")
time.sleep(0.01)