-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress.py
37 lines (25 loc) · 893 Bytes
/
progress.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
"""
Simple package to show generation progress
"""
ESC = "\x1B"
SGR_FG_BLUE = f"{ESC}[34m"
SGR_RESET = f"{ESC}[0m"
_current_step_name: str | None = None
StepHandle = int
_current_step: StepHandle = 1
def begin_step(step_name: str) -> StepHandle:
global _current_step_name, _current_step
step = _current_step
if _current_step_name != step_name:
_current_step_name = step_name
_print_step(step_name)
step += 1
_current_step = step
return step
def step_progress(step: StepHandle, subtask_name: str, progress: int, total: int):
if _current_step == step:
_print_step_progress(subtask_name, progress, total)
def _print_step(step_name: str) -> None:
print(f"{SGR_FG_BLUE}::{SGR_RESET} {step_name}")
def _print_step_progress(subtask_name: str, progress: int, total: int):
print(f" - ({progress}/{total}) {subtask_name}")