Skip to content

Commit

Permalink
Merge pull request #3220 from Haskely/master
Browse files Browse the repository at this point in the history
Add 'completed' parameter to 'track' function for resumable progress
  • Loading branch information
willmcgugan authored Jul 1, 2024
2 parents 260f18a + d0a9962 commit b8975c5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rich/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def track(
sequence: Union[Sequence[ProgressType], Iterable[ProgressType]],
description: str = "Working...",
total: Optional[float] = None,
completed: int = 0,
auto_refresh: bool = True,
console: Optional[Console] = None,
transient: bool = False,
Expand All @@ -123,6 +124,7 @@ def track(
sequence (Iterable[ProgressType]): A sequence (must support "len") you wish to iterate over.
description (str, optional): Description of task show next to progress bar. Defaults to "Working".
total: (float, optional): Total number of steps. Default is len(sequence).
completed (int, optional): Number of steps completed so far. Defaults to 0.
auto_refresh (bool, optional): Automatic refresh, disable to force a refresh after each iteration. Default is True.
transient: (bool, optional): Clear the progress on exit. Defaults to False.
console (Console, optional): Console to write to. Default creates internal Console instance.
Expand Down Expand Up @@ -166,7 +168,7 @@ def track(

with progress:
yield from progress.track(
sequence, total=total, description=description, update_period=update_period
sequence, total=total, completed=completed, description=description, update_period=update_period
)


Expand Down Expand Up @@ -1180,6 +1182,7 @@ def track(
self,
sequence: Union[Iterable[ProgressType], Sequence[ProgressType]],
total: Optional[float] = None,
completed: int = 0,
task_id: Optional[TaskID] = None,
description: str = "Working...",
update_period: float = 0.1,
Expand All @@ -1189,6 +1192,7 @@ def track(
Args:
sequence (Sequence[ProgressType]): A sequence of values you want to iterate over and track progress.
total: (float, optional): Total number of steps. Default is len(sequence).
completed (int, optional): Number of steps completed so far. Defaults to 0.
task_id: (TaskID): Task to track. Default is new task.
description: (str, optional): Description of task, if new task is created.
update_period (float, optional): Minimum time (in seconds) between calls to update(). Defaults to 0.1.
Expand All @@ -1200,9 +1204,9 @@ def track(
total = float(length_hint(sequence)) or None

if task_id is None:
task_id = self.add_task(description, total=total)
task_id = self.add_task(description, total=total, completed=completed)
else:
self.update(task_id, total=total)
self.update(task_id, total=total, completed=completed)

if self.live.auto_refresh:
with _TrackThread(self, task_id, update_period) as track_thread:
Expand Down

0 comments on commit b8975c5

Please sign in to comment.