Spaces:
Sleeping
Sleeping
Download venv/lib/python3.14/site-packages/rich/constrain.py from HSR-DeepThink/Perhance: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/spaces/HSR-DeepThink/Perhance/resolve/main/venv/lib/python3.14/site-packages/rich/constrain.py
- Command line
-
hf download hf://spaces/HSR-DeepThink/Perhance/venv/lib/python3.14/site-packages/rich/constrain.py
-
curl -L -o constrain.py https://huggingface.co/spaces/HSR-DeepThink/Perhance/resolve/main/venv/lib/python3.14/site-packages/rich/constrain.py
1.29 kB
| from typing import Optional, TYPE_CHECKING | |
| from .jupyter import JupyterMixin | |
| from .measure import Measurement | |
| if TYPE_CHECKING: | |
| from .console import Console, ConsoleOptions, RenderableType, RenderResult | |
| class Constrain(JupyterMixin): | |
| """Constrain the width of a renderable to a given number of characters. | |
| Args: | |
| renderable (RenderableType): A renderable object. | |
| width (int, optional): The maximum width (in characters) to render. Defaults to 80. | |
| """ | |
| def __init__(self, renderable: "RenderableType", width: Optional[int] = 80) -> None: | |
| self.renderable = renderable | |
| self.width = width | |
| def __rich_console__( | |
| self, console: "Console", options: "ConsoleOptions" | |
| ) -> "RenderResult": | |
| if self.width is None: | |
| yield self.renderable | |
| else: | |
| child_options = options.update_width(min(self.width, options.max_width)) | |
| yield from console.render(self.renderable, child_options) | |
| def __rich_measure__( | |
| self, console: "Console", options: "ConsoleOptions" | |
| ) -> "Measurement": | |
| if self.width is not None: | |
| options = options.update_width(self.width) | |
| measurement = Measurement.get(console, options, self.renderable) | |
| return measurement | |