-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
_rich_progress.py
54 lines (46 loc) 路 1.38 KB
/
_rich_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from funcy import split
from rich.progress import (
BarColumn,
DownloadColumn,
MofNCompleteColumn,
Progress,
TextColumn,
TimeElapsedColumn,
TimeRemainingColumn,
TransferSpeedColumn,
)
class MofNCompleteColumnWithUnit(MofNCompleteColumn):
"""Requires `task.fields[unit]` to be set."""
def render(self, task):
ret = super().render(task)
unit = task.fields.get("unit")
return ret.append(f" {unit}") if unit else ret
class RichProgress(Progress):
def clear_task(self, task):
try:
self.remove_task(task)
except KeyError:
pass
class RichTransferProgress(RichProgress):
SUMMARY_COLS = (
TextColumn("[magenta]{task.description}[bold green]"),
MofNCompleteColumnWithUnit(),
TimeElapsedColumn(),
)
TRANSFER_COLS = (
TextColumn(" [blue]{task.description}"),
BarColumn(),
DownloadColumn(),
TransferSpeedColumn(),
TextColumn("eta"),
TimeRemainingColumn(),
)
def get_renderables(self):
summary_tasks, other_tasks = split(
lambda task: task.fields.get("progress_type") == "summary",
self.tasks,
)
self.columns = self.SUMMARY_COLS
yield self.make_tasks_table(summary_tasks)
self.columns = self.TRANSFER_COLS
yield self.make_tasks_table(other_tasks)