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

Method __rich_console__

rich/panel.py:141–275  ·  view source on GitHub ↗
(
        self, console: "Console", options: "ConsoleOptions"
    )

Source from the content-addressed store, hash-verified

139 return None
140
141 def __rich_console__(
142 self, console: "Console", options: "ConsoleOptions"
143 ) -> "RenderResult":
144 _padding = Padding.unpack(self.padding)
145 renderable = (
146 Padding(self.renderable, _padding) if any(_padding) else self.renderable
147 )
148 style = console.get_style(self.style)
149 border_style = style + console.get_style(self.border_style)
150 width = (
151 options.max_width
152 if self.width is None
153 else min(options.max_width, self.width)
154 )
155
156 safe_box: bool = console.safe_box if self.safe_box is None else self.safe_box
157 box = self.box.substitute(options, safe=safe_box)
158
159 def align_text(
160 text: Text, width: int, align: str, character: str, style: Style
161 ) -> Text:
162 """Gets new aligned text.
163
164 Args:
165 text (Text): Title or subtitle text.
166 width (int): Desired width.
167 align (str): Alignment.
168 character (str): Character for alignment.
169 style (Style): Border style
170
171 Returns:
172 Text: New text instance
173 """
174 text = text.copy()
175 text.truncate(width)
176 excess_space = width - cell_len(text.plain)
177 if text.style:
178 text.stylize(console.get_style(text.style))
179
180 if excess_space:
181 if align == "left":
182 return Text.assemble(
183 text,
184 (character * excess_space, style),
185 no_wrap=True,
186 end="",
187 )
188 elif align == "center":
189 left = excess_space // 2
190 return Text.assemble(
191 (character * left, style),
192 text,
193 (character * (excess_space - left), style),
194 no_wrap=True,
195 end="",
196 )
197 else:
198 return Text.assemble(

Callers

nothing calls this directly

Calls 14

PaddingClass · 0.85
SegmentClass · 0.85
unpackMethod · 0.80
get_styleMethod · 0.80
substituteMethod · 0.80
stylize_beforeMethod · 0.80
measureMethod · 0.80
update_widthMethod · 0.80
render_linesMethod · 0.80
get_topMethod · 0.80
get_bottomMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected