Renders a (progress) bar. Used by rich.progress. Args: total (float, optional): Number of steps in the bar. Defaults to 100. Set to None to render a pulsing animation. completed (float, optional): Number of steps completed. Defaults to 0. width (int, optional): Width of
| 16 | |
| 17 | |
| 18 | class ProgressBar(JupyterMixin): |
| 19 | """Renders a (progress) bar. Used by rich.progress. |
| 20 | |
| 21 | Args: |
| 22 | total (float, optional): Number of steps in the bar. Defaults to 100. Set to None to render a pulsing animation. |
| 23 | completed (float, optional): Number of steps completed. Defaults to 0. |
| 24 | width (int, optional): Width of the bar, or ``None`` for maximum width. Defaults to None. |
| 25 | pulse (bool, optional): Enable pulse effect. Defaults to False. Will pulse if a None total was passed. |
| 26 | style (StyleType, optional): Style for the bar background. Defaults to "bar.back". |
| 27 | complete_style (StyleType, optional): Style for the completed bar. Defaults to "bar.complete". |
| 28 | finished_style (StyleType, optional): Style for a finished bar. Defaults to "bar.finished". |
| 29 | pulse_style (StyleType, optional): Style for pulsing bars. Defaults to "bar.pulse". |
| 30 | animation_time (Optional[float], optional): Time in seconds to use for animation, or None to use system time. |
| 31 | """ |
| 32 | |
| 33 | def __init__( |
| 34 | self, |
| 35 | total: Optional[float] = 100.0, |
| 36 | completed: float = 0, |
| 37 | width: Optional[int] = None, |
| 38 | pulse: bool = False, |
| 39 | style: StyleType = "bar.back", |
| 40 | complete_style: StyleType = "bar.complete", |
| 41 | finished_style: StyleType = "bar.finished", |
| 42 | pulse_style: StyleType = "bar.pulse", |
| 43 | animation_time: Optional[float] = None, |
| 44 | ): |
| 45 | self.total = total |
| 46 | self.completed = completed |
| 47 | self.width = width |
| 48 | self.pulse = pulse |
| 49 | self.style = style |
| 50 | self.complete_style = complete_style |
| 51 | self.finished_style = finished_style |
| 52 | self.pulse_style = pulse_style |
| 53 | self.animation_time = animation_time |
| 54 | |
| 55 | self._pulse_segments: Optional[List[Segment]] = None |
| 56 | |
| 57 | def __repr__(self) -> str: |
| 58 | return f"<Bar {self.completed!r} of {self.total!r}>" |
| 59 | |
| 60 | @property |
| 61 | def percentage_completed(self) -> Optional[float]: |
| 62 | """Calculate percentage complete.""" |
| 63 | if self.total is None: |
| 64 | return None |
| 65 | completed = (self.completed / self.total) * 100.0 |
| 66 | completed = min(100, max(0.0, completed)) |
| 67 | return completed |
| 68 | |
| 69 | @lru_cache(maxsize=16) |
| 70 | def _get_pulse_segments( |
| 71 | self, |
| 72 | fore_style: Style, |
| 73 | back_style: Style, |
| 74 | color_system: str, |
| 75 | no_color: bool, |
no outgoing calls