1
1
mirror of https://github.com/OpenVoiceOS/OpenVoiceOS synced 2025-06-05 22:19:21 +02:00

[WIP] Pushed for backup.

... Do not build this as of yet ...
This commit is contained in:
j1nx
2023-06-01 15:16:04 +02:00
parent 5c7af8b058
commit c6460b9307
417 changed files with 43487 additions and 76 deletions

View File

@ -0,0 +1,37 @@
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