1from typing
import TYPE_CHECKING, Optional
3from .align
import AlignMethod
4from .box
import ROUNDED, Box
5from .cells
import cell_len
6from .jupyter
import JupyterMixin
7from .measure
import Measurement, measure_renderables
8from .padding
import Padding, PaddingDimensions
9from .segment
import Segment
10from .style
import Style, StyleType
11from .text
import Text, TextType
14 from .console
import Console, ConsoleOptions, RenderableType, RenderResult
18 """A console renderable that draws a border around its contents.
21 >>> console.print(Panel("Hello, World!"))
24 renderable (RenderableType): A console renderable object.
25 box (Box, optional): A Box instance that defines the look of the border (see :ref:`appendix_box`.
26 Defaults to box.ROUNDED.
27 safe_box (bool, optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.
28 expand (bool, optional): If True the panel will stretch to fill the console
29 width, otherwise it will be sized to fit the contents. Defaults to True.
30 style (str, optional): The style of the panel (border and contents). Defaults to "none".
31 border_style (str, optional): The style of the border. Defaults to "none".
32 width (Optional[int], optional): Optional width of panel. Defaults to None to auto-detect.
33 height (Optional[int], optional): Optional height of panel. Defaults to None to auto-detect.
34 padding (Optional[PaddingDimensions]): Optional padding around renderable. Defaults to 0.
35 highlight (bool, optional): Enable automatic highlighting of panel title (if str). Defaults to False.
40 renderable:
"RenderableType",
43 title: Optional[TextType] =
None,
44 title_align: AlignMethod =
"center",
45 subtitle: Optional[TextType] =
None,
46 subtitle_align: AlignMethod =
"center",
47 safe_box: Optional[bool] =
None,
49 style: StyleType =
"none",
50 border_style: StyleType =
"none",
51 width: Optional[int] =
None,
52 height: Optional[int] =
None,
53 padding: PaddingDimensions = (0, 1),
54 highlight: bool =
False,
74 renderable:
"RenderableType",
77 title: Optional[TextType] =
None,
78 title_align: AlignMethod =
"center",
79 subtitle: Optional[TextType] =
None,
80 subtitle_align: AlignMethod =
"center",
81 safe_box: Optional[bool] =
None,
82 style: StyleType =
"none",
83 border_style: StyleType =
"none",
84 width: Optional[int] =
None,
85 padding: PaddingDimensions = (0, 1),
87 """An alternative constructor that sets expand=False."""
92 title_align=title_align,
94 subtitle_align=subtitle_align,
97 border_style=border_style,
109 else self.
title.copy()
136 self, console:
"Console", options:
"ConsoleOptions"
146 if self.
width is None
151 box = self.
box.substitute(options, safe=safe_box)
154 text: Text, width: int, align: str, character: str, style: Style
156 """Gets new aligned text.
159 text (Text): Title or subtitle text.
160 width (int): Desired width.
161 align (str): Alignment.
162 character (str): Character for alignment.
163 style (Style): Border style
166 Text: New text instance
175 (character * excess_space, style),
179 elif align ==
"center":
180 left = excess_space // 2
182 (character * left, style),
184 (character * (excess_space - left), style),
190 (character * excess_space, style),
198 if title_text
is not None:
211 if title_text
is not None:
216 width = child_width + 2
218 width=child_width, height=child_height, highlight=self.
highlight
223 line_end =
Segment(f
"{box.mid_right}", border_style)
225 if title_text
is None or width <= 4:
247 if subtitle_text
is not None:
250 if subtitle_text
is None or width <= 4:
269 self, console:
"Console", options:
"ConsoleOptions"
273 padding = left + right
276 if self.
width is None:
291if __name__ ==
"__main__":
292 from .console
import Console
296 from .box
import DOUBLE, ROUNDED
297 from .padding
import Padding
302 style=
"white on blue",
Optional[Text] _subtitle(self)
"Measurement" __rich_measure__(self, "Console" console, "ConsoleOptions" options)
Optional[Text] _title(self)
"RenderResult" __rich_console__(self, "Console" console, "ConsoleOptions" options)
"Panel" fit(cls, "RenderableType" renderable, Box box=ROUNDED, *Optional[TextType] title=None, AlignMethod title_align="center", Optional[TextType] subtitle=None, AlignMethod subtitle_align="center", Optional[bool] safe_box=None, StyleType style="none", StyleType border_style="none", Optional[int] width=None, PaddingDimensions padding=(0, 1))
None __init__(self, "RenderableType" renderable, Box box=ROUNDED, *Optional[TextType] title=None, AlignMethod title_align="center", Optional[TextType] subtitle=None, AlignMethod subtitle_align="center", Optional[bool] safe_box=None, bool expand=True, StyleType style="none", StyleType border_style="none", Optional[int] width=None, Optional[int] height=None, PaddingDimensions padding=(0, 1), bool highlight=False)