forked from kenzuya/unshackle
fix(progress): force track bar completion on terminal states
This commit is contained in:
@@ -95,7 +95,7 @@ class Tracks:
|
|||||||
|
|
||||||
return rep
|
return rep
|
||||||
|
|
||||||
def tree(self, add_progress: bool = False) -> tuple[Tree, list[partial]]:
|
def tree(self, add_progress: bool = False) -> tuple[Tree, list[Callable[..., None]]]:
|
||||||
all_tracks = [*list(self), *self.chapters, *self.attachments]
|
all_tracks = [*list(self), *self.chapters, *self.attachments]
|
||||||
|
|
||||||
progress_callables = []
|
progress_callables = []
|
||||||
@@ -121,7 +121,26 @@ class Tracks:
|
|||||||
speed_estimate_period=10,
|
speed_estimate_period=10,
|
||||||
)
|
)
|
||||||
task = progress.add_task("", downloaded="-")
|
task = progress.add_task("", downloaded="-")
|
||||||
progress_callables.append(partial(progress.update, task_id=task))
|
|
||||||
|
current_total = 100.0
|
||||||
|
|
||||||
|
def update_track_progress(task_id: int = task, **kwargs) -> None:
|
||||||
|
"""
|
||||||
|
Ensure terminal status states render as a fully completed bar.
|
||||||
|
|
||||||
|
Some downloaders can report completed slightly below total
|
||||||
|
before emitting the final "Downloaded" state.
|
||||||
|
"""
|
||||||
|
nonlocal current_total
|
||||||
|
if "total" in kwargs and kwargs["total"] is not None:
|
||||||
|
current_total = kwargs["total"]
|
||||||
|
|
||||||
|
downloaded_state = kwargs.get("downloaded")
|
||||||
|
if downloaded_state in {"Downloaded", "Decrypted", "[yellow]SKIPPED"}:
|
||||||
|
kwargs["completed"] = current_total
|
||||||
|
progress.update(task_id=task_id, **kwargs)
|
||||||
|
|
||||||
|
progress_callables.append(update_track_progress)
|
||||||
track_table = Table.grid()
|
track_table = Table.grid()
|
||||||
track_table.add_row(str(track)[6:], style="text2")
|
track_table.add_row(str(track)[6:], style="text2")
|
||||||
track_table.add_row(progress)
|
track_table.add_row(progress)
|
||||||
|
|||||||
Reference in New Issue
Block a user