MCPcopy
hub / github.com/Textualize/rich / Constrain

Class Constrain

rich/constrain.py:10–37  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

8
9
10class Constrain(JupyterMixin):
11 """Constrain the width of a renderable to a given number of characters.
12
13 Args:
14 renderable (RenderableType): A renderable object.
15 width (int, optional): The maximum width (in characters) to render. Defaults to 80.
16 """
17
18 def __init__(self, renderable: "RenderableType", width: Optional[int] = 80) -> None:
19 self.renderable = renderable
20 self.width = width
21
22 def __rich_console__(
23 self, console: "Console", options: "ConsoleOptions"
24 ) -> "RenderResult":
25 if self.width is None:
26 yield self.renderable
27 else:
28 child_options = options.update_width(min(self.width, options.max_width))
29 yield from console.render(self.renderable, child_options)
30
31 def __rich_measure__(
32 self, console: "Console", options: "ConsoleOptions"
33 ) -> "Measurement":
34 if self.width is not None:
35 options = options.update_width(self.width)
36 measurement = Measurement.get(console, options, self.renderable)
37 return measurement

Callers 4

test_width_of_noneFunction · 0.90
__rich_console__Method · 0.85
render_stackMethod · 0.85
__rich_console__Method · 0.85

Calls

no outgoing calls

Tested by 1

test_width_of_noneFunction · 0.72