Get a measurement for a renderable. Args: console (~rich.console.Console): Console instance. options (~rich.console.ConsoleOptions): Console options. renderable (RenderableType): An object that may be rendered with Rich. Raises: error
(
cls, console: "Console", options: "ConsoleOptions", renderable: "RenderableType"
)
| 77 | |
| 78 | @classmethod |
| 79 | def get( |
| 80 | cls, console: "Console", options: "ConsoleOptions", renderable: "RenderableType" |
| 81 | ) -> "Measurement": |
| 82 | """Get a measurement for a renderable. |
| 83 | |
| 84 | Args: |
| 85 | console (~rich.console.Console): Console instance. |
| 86 | options (~rich.console.ConsoleOptions): Console options. |
| 87 | renderable (RenderableType): An object that may be rendered with Rich. |
| 88 | |
| 89 | Raises: |
| 90 | errors.NotRenderableError: If the object is not renderable. |
| 91 | |
| 92 | Returns: |
| 93 | Measurement: Measurement object containing range of character widths required to render the object. |
| 94 | """ |
| 95 | _max_width = options.max_width |
| 96 | if _max_width < 1: |
| 97 | return Measurement(0, 0) |
| 98 | if isinstance(renderable, str): |
| 99 | renderable = console.render_str( |
| 100 | renderable, markup=options.markup, highlight=False |
| 101 | ) |
| 102 | renderable = rich_cast(renderable) |
| 103 | if is_renderable(renderable): |
| 104 | get_console_width: Optional[ |
| 105 | Callable[["Console", "ConsoleOptions"], "Measurement"] |
| 106 | ] = getattr(renderable, "__rich_measure__", None) |
| 107 | if get_console_width is not None: |
| 108 | render_width = ( |
| 109 | get_console_width(console, options) |
| 110 | .normalize() |
| 111 | .with_maximum(_max_width) |
| 112 | ) |
| 113 | if render_width.maximum < 1: |
| 114 | return Measurement(0, 0) |
| 115 | return render_width.normalize() |
| 116 | else: |
| 117 | return Measurement(0, _max_width) |
| 118 | else: |
| 119 | raise errors.NotRenderableError( |
| 120 | f"Unable to get render width for {renderable!r}; " |
| 121 | "a str, Segment, or object with __rich_console__ method is required" |
| 122 | ) |
| 123 | |
| 124 | |
| 125 | def measure_renderables( |
nothing calls this directly
no test coverage detected