Renders estimated time remaining. Args: compact (bool, optional): Render MM:SS when time remaining is less than an hour. Defaults to False. elapsed_when_finished (bool, optional): Render time elapsed when the task is finished. Defaults to False.
| 770 | |
| 771 | |
| 772 | class TimeRemainingColumn(ProgressColumn): |
| 773 | """Renders estimated time remaining. |
| 774 | |
| 775 | Args: |
| 776 | compact (bool, optional): Render MM:SS when time remaining is less than an hour. Defaults to False. |
| 777 | elapsed_when_finished (bool, optional): Render time elapsed when the task is finished. Defaults to False. |
| 778 | """ |
| 779 | |
| 780 | # Only refresh twice a second to prevent jitter |
| 781 | max_refresh = 0.5 |
| 782 | |
| 783 | def __init__( |
| 784 | self, |
| 785 | compact: bool = False, |
| 786 | elapsed_when_finished: bool = False, |
| 787 | table_column: Optional[Column] = None, |
| 788 | ): |
| 789 | self.compact = compact |
| 790 | self.elapsed_when_finished = elapsed_when_finished |
| 791 | super().__init__(table_column=table_column) |
| 792 | |
| 793 | def render(self, task: "Task") -> Text: |
| 794 | """Show time remaining.""" |
| 795 | if self.elapsed_when_finished and task.finished: |
| 796 | task_time = task.finished_time |
| 797 | style = "progress.elapsed" |
| 798 | else: |
| 799 | task_time = task.time_remaining |
| 800 | style = "progress.remaining" |
| 801 | |
| 802 | if task.total is None: |
| 803 | return Text("", style=style) |
| 804 | |
| 805 | if task_time is None: |
| 806 | return Text("--:--" if self.compact else "-:--:--", style=style) |
| 807 | |
| 808 | # Based on https://github.com/tqdm/tqdm/blob/master/tqdm/std.py |
| 809 | minutes, seconds = divmod(int(task_time), 60) |
| 810 | hours, minutes = divmod(minutes, 60) |
| 811 | |
| 812 | if self.compact and not hours: |
| 813 | formatted = f"{minutes:02d}:{seconds:02d}" |
| 814 | else: |
| 815 | formatted = f"{hours:d}:{minutes:02d}:{seconds:02d}" |
| 816 | |
| 817 | return Text(formatted, style=style) |
| 818 | |
| 819 | |
| 820 | class FileSizeColumn(ProgressColumn): |
no outgoing calls