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

Class Columns

rich/columns.py:16–171  ·  view source on GitHub ↗

Display renderables in neat columns. Args: renderables (Iterable[RenderableType]): Any number of Rich renderables (including str). width (int, optional): The desired width of the columns, or None to auto detect. Defaults to None. padding (PaddingDimensions, optional): Op

Source from the content-addressed store, hash-verified

14
15
16class Columns(JupyterMixin):
17 """Display renderables in neat columns.
18
19 Args:
20 renderables (Iterable[RenderableType]): Any number of Rich renderables (including str).
21 width (int, optional): The desired width of the columns, or None to auto detect. Defaults to None.
22 padding (PaddingDimensions, optional): Optional padding around cells. Defaults to (0, 1).
23 expand (bool, optional): Expand columns to full width. Defaults to False.
24 equal (bool, optional): Arrange in to equal sized columns. Defaults to False.
25 column_first (bool, optional): Align items from top to bottom (rather than left to right). Defaults to False.
26 right_to_left (bool, optional): Start column from right hand side. Defaults to False.
27 align (str, optional): Align value ("left", "right", or "center") or None for default. Defaults to None.
28 title (TextType, optional): Optional title for Columns.
29 """
30
31 def __init__(
32 self,
33 renderables: Optional[Iterable[RenderableType]] = None,
34 padding: PaddingDimensions = (0, 1),
35 *,
36 width: Optional[int] = None,
37 expand: bool = False,
38 equal: bool = False,
39 column_first: bool = False,
40 right_to_left: bool = False,
41 align: Optional[AlignMethod] = None,
42 title: Optional[TextType] = None,
43 ) -> None:
44 self.renderables = list(renderables or [])
45 self.width = width
46 self.padding = padding
47 self.expand = expand
48 self.equal = equal
49 self.column_first = column_first
50 self.right_to_left = right_to_left
51 self.align: Optional[AlignMethod] = align
52 self.title = title
53
54 def add_renderable(self, renderable: RenderableType) -> None:
55 """Add a renderable to the columns.
56
57 Args:
58 renderable (RenderableType): Any renderable object.
59 """
60 self.renderables.append(renderable)
61
62 def __rich_console__(
63 self, console: Console, options: ConsoleOptions
64 ) -> RenderResult:
65 render_str = console.render_str
66 renderables = [
67 render_str(renderable) if isinstance(renderable, str) else renderable
68 for renderable in self.renderables
69 ]
70 if not renderables:
71 return
72 _top, right, _bottom, left = Padding.unpack(self.padding)
73 width_padding = max(left, right)

Callers 10

renderFunction · 0.90
renderFunction · 0.90
columns.pyFile · 0.90
spinners.pyFile · 0.90
listdir.pyFile · 0.90
print_calendarFunction · 0.90
emoji.pyFile · 0.90
box.pyFile · 0.90
columns.pyFile · 0.85
_render_stackMethod · 0.85

Calls

no outgoing calls

Tested by 2

renderFunction · 0.72
renderFunction · 0.72