A spinner animation. Args: name (str): Name of spinner (run python -m rich.spinner). text (RenderableType, optional): A renderable to display at the right of the spinner (str or Text typically). Defaults to "". style (StyleType, optional): Style for spinner animation. De
| 11 | |
| 12 | |
| 13 | class Spinner: |
| 14 | """A spinner animation. |
| 15 | |
| 16 | Args: |
| 17 | name (str): Name of spinner (run python -m rich.spinner). |
| 18 | text (RenderableType, optional): A renderable to display at the right of the spinner (str or Text typically). Defaults to "". |
| 19 | style (StyleType, optional): Style for spinner animation. Defaults to None. |
| 20 | speed (float, optional): Speed factor for animation. Defaults to 1.0. |
| 21 | |
| 22 | Raises: |
| 23 | KeyError: If name isn't one of the supported spinner animations. |
| 24 | """ |
| 25 | |
| 26 | def __init__( |
| 27 | self, |
| 28 | name: str, |
| 29 | text: "RenderableType" = "", |
| 30 | *, |
| 31 | style: Optional["StyleType"] = None, |
| 32 | speed: float = 1.0, |
| 33 | ) -> None: |
| 34 | try: |
| 35 | spinner = SPINNERS[name] |
| 36 | except KeyError: |
| 37 | raise KeyError(f"no spinner called {name!r}") |
| 38 | self.text: "Union[RenderableType, Text]" = ( |
| 39 | Text.from_markup(text) if isinstance(text, str) else text |
| 40 | ) |
| 41 | self.name = name |
| 42 | self.frames = cast(List[str], spinner["frames"])[:] |
| 43 | self.interval = cast(float, spinner["interval"]) |
| 44 | self.start_time: Optional[float] = None |
| 45 | self.style = style |
| 46 | self.speed = speed |
| 47 | self.frame_no_offset: float = 0.0 |
| 48 | self._update_speed = 0.0 |
| 49 | |
| 50 | def __rich_console__( |
| 51 | self, console: "Console", options: "ConsoleOptions" |
| 52 | ) -> "RenderResult": |
| 53 | yield self.render(console.get_time()) |
| 54 | |
| 55 | def __rich_measure__( |
| 56 | self, console: "Console", options: "ConsoleOptions" |
| 57 | ) -> Measurement: |
| 58 | text = self.render(0) |
| 59 | return Measurement.get(console, options, text) |
| 60 | |
| 61 | def render(self, time: float) -> "RenderableType": |
| 62 | """Render the spinner for a given time. |
| 63 | |
| 64 | Args: |
| 65 | time (float): Time in seconds. |
| 66 | |
| 67 | Returns: |
| 68 | RenderableType: A renderable containing animation frame. |
| 69 | """ |
| 70 | if self.start_time is None: |
no outgoing calls