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

Class Padding

rich/padding.py:19–135  ·  rich/padding.py::Padding

Draw space around content. Example: >>> print(Padding("Hello", (2, 4), style="on blue")) Args: renderable (RenderableType): String or other renderable. pad (Union[int, Tuple[int]]): Padding for top, right, bottom, and left borders. May be specified with

Source from the content-addressed store, hash-verified

17
18
19class Padding(JupyterMixin):
20 class="st">"""Draw space around content.
21
22 Example:
23 >>> print(Padding(class="st">"Hello", (2, 4), style=class="st">"on blue"))
24
25 Args:
26 renderable (RenderableType): String or other renderable.
27 pad (Union[int, Tuple[int]]): Padding for top, right, bottom, and left borders.
28 May be specified with 1, 2, or 4 integers (CSS style).
29 style (Union[str, Style], optional): Style for padding characters. Defaults to class="st">"none".
30 expand (bool, optional): Expand padding to fit available width. Defaults to True.
31 class="st">"""
32
33 def __init__(
34 self,
35 renderable: class="st">"RenderableType",
36 pad: class="st">"PaddingDimensions" = (0, 0, 0, 0),
37 *,
38 style: Union[str, Style] = class="st">"none",
39 expand: bool = True,
40 ):
41 self.renderable = renderable
42 self.top, self.right, self.bottom, self.left = self.unpack(pad)
43 self.style = style
44 self.expand = expand
45
46 @classmethod
47 def indent(cls, renderable: class="st">"RenderableType", level: int) -> class="st">"Padding":
48 class="st">"""Make padding instance to render an indent.
49
50 Args:
51 renderable (RenderableType): String or other renderable.
52 level (int): Number of characters to indent.
53
54 Returns:
55 Padding: A Padding instance.
56 class="st">"""
57
58 return Padding(renderable, pad=(0, 0, 0, level), expand=False)
59
60 @staticmethod
61 def unpack(pad: class="st">"PaddingDimensions") -> Tuple[int, int, int, int]:
62 class="st">""class="st">"Unpack padding specified in CSS style."class="st">""
63 if isinstance(pad, int):
64 return (pad, pad, pad, pad)
65 if len(pad) == 1:
66 _pad = pad[0]
67 return (_pad, _pad, _pad, _pad)
68 if len(pad) == 2:
69 pad_top, pad_right = pad
70 return (pad_top, pad_right, pad_top, pad_right)
71 if len(pad) == 4:
72 top, right, bottom, left = pad
73 return (top, right, bottom, left)
74 raise ValueError(fclass="st">"1, 2 or 4 integers required for padding; {len(pad)} given")
75
76 def __repr__(self) -> str:

Callers 9

test_reprFunction · 0.90
test_expand_falseFunction · 0.90
test_rich_consoleFunction · 0.90
padding.pyFile · 0.90
__rich_console__Method · 0.90
__rich_console__Method · 0.85
indentMethod · 0.85
padding.pyFile · 0.85

Calls

no outgoing calls

Tested by 4

test_reprFunction · 0.72
test_expand_falseFunction · 0.72
test_rich_consoleFunction · 0.72