Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/unblob/ui.py: 63%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from typing import Protocol
3from rich import progress
4from rich.style import Style
6from .models import TaskResult
9class ProgressReporter(Protocol):
10 def __enter__(self): ...
12 def __exit__(self, _exc_type, _exc_value, _tb): ...
14 def update(self, result: TaskResult): ...
17class NullProgressReporter:
18 def __enter__(self):
19 pass
21 def __exit__(self, _exc_type, _exc_value, _tb):
22 pass
24 def update(self, result: TaskResult):
25 pass
28class RichConsoleProgressReporter:
29 def __init__(self):
30 self._progress = progress.Progress(
31 progress.TextColumn(
32 "Extraction progress: {task.percentage:>3.0f}%",
33 style=Style(color="#00FFC8"),
34 ),
35 progress.BarColumn(
36 complete_style=Style(color="#00FFC8"), style=Style(color="#002060")
37 ),
38 )
39 self._overall_progress_task = self._progress.add_task("Extraction progress:")
41 def __enter__(self):
42 self._progress.start()
44 def __exit__(self, _exc_type, _exc_value, _tb):
45 self._progress.remove_task(self._overall_progress_task)
46 self._progress.stop()
48 def update(self, result: TaskResult):
49 if (total := self._progress.tasks[0].total) is not None:
50 self._progress.update(
51 self._overall_progress_task,
52 advance=1,
53 total=total + len(result.subtasks),
54 )