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

Class Align

rich/align.py:17–239  ·  rich/align.py::Align

Align a renderable by adding spaces if necessary. Args: renderable (RenderableType): A console renderable. align (AlignMethod): One of "left", "center", or "right"" style (StyleType, optional): An optional style to apply to the background. vertical (Optional[Vert

Source from the content-addressed store, hash-verified

15
16
17class Align(JupyterMixin):
18 class="st">"""Align a renderable by adding spaces if necessary.
19
20 Args:
21 renderable (RenderableType): A console renderable.
22 align (AlignMethod): One of class="st">"left", class="st">"center", or class="st">"right""
23 style (StyleType, optional): An optional style to apply to the background.
24 vertical (Optional[VerticalAlignMethod], optional): Optional vertical align, one of class="st">"top", class="st">"middle", or class="st">"bottom". Defaults to None.
25 pad (bool, optional): Pad the right with spaces. Defaults to True.
26 width (int, optional): Restrict contents to given width, or None to use default width. Defaults to None.
27 height (int, optional): Set height of align renderable, or None to fit to contents. Defaults to None.
28
29 Raises:
30 ValueError: if ``align`` is not one of the expected values.
31
32 Example:
33 .. code-block:: python
34
35 from rich.console import Console
36 from rich.align import Align
37 from rich.panel import Panel
38
39 console = Console()
40 class="cm"># Create a panel 20 characters wide
41 p = Panel(class="st">"Hello, [b]World[/b]!", style=class="st">"on green", width=20)
42
43 class="cm"># Renders the panel centered in the terminal
44 console.print(Align(p, align=class="st">"center"))
45 class="st">"""
46
47 def __init__(
48 self,
49 renderable: class="st">"RenderableType",
50 align: AlignMethod = class="st">"left",
51 style: Optional[StyleType] = None,
52 *,
53 vertical: Optional[VerticalAlignMethod] = None,
54 pad: bool = True,
55 width: Optional[int] = None,
56 height: Optional[int] = None,
57 ) -> None:
58 if align not in (class="st">"left", class="st">"center", class="st">"right"):
59 raise ValueError(
60 f&class="cm">#x27;invalid value for align, expected class="st">"left", class="st">"center", or class="st">"right" (not {align!r})'
61 )
62 if vertical is not None and vertical not in (class="st">"top", class="st">"middle", class="st">"bottom"):
63 raise ValueError(
64 f&class="cm">#x27;invalid value for vertical, expected class="st">"top", class="st">"middle", or class="st">"bottom" (not {vertical!r})'
65 )
66 self.renderable = renderable
67 self.align = align
68 self.style = style
69 self.vertical = vertical
70 self.pad = pad
71 self.width = width
72 self.height = height
73
74 def __repr__(self) -> str:

Callers 15

test_bad_align_legalFunction · 0.90
test_reprFunction · 0.90
test_align_leftFunction · 0.90
test_align_centerFunction · 0.90
test_align_rightFunction · 0.90
test_align_topFunction · 0.90
test_align_middleFunction · 0.90
test_align_bottomFunction · 0.90
test_align_center_middleFunction · 0.90
test_align_fitFunction · 0.90
test_align_right_styleFunction · 0.90
test_measureFunction · 0.90

Calls

no outgoing calls

Tested by 14

test_bad_align_legalFunction · 0.72
test_reprFunction · 0.72
test_align_leftFunction · 0.72
test_align_centerFunction · 0.72
test_align_rightFunction · 0.72
test_align_topFunction · 0.72
test_align_middleFunction · 0.72
test_align_bottomFunction · 0.72
test_align_center_middleFunction · 0.72
test_align_fitFunction · 0.72
test_align_right_styleFunction · 0.72
test_measureFunction · 0.72