from .align import AlignMethod from .box import ROUNDED, Box from .cells import cell_len from .jupyter import JupyterMixin from .measure import Measurement, measure_renderables from .padding import Padding, PaddingDimensions from .segment import Segment from .style import Style, StyleType from .text import Text, TextType
if TYPE_CHECKING: from .console import Console, ConsoleOptions, RenderableType, RenderResult
class Panel(JupyterMixin): """A console renderable that draws a border around its contents.
Args:
renderable (RenderableType): A console renderable object.
box (Box, optional): A Box instance that defines the look of the border (see :ref:`appendix_box`.
Defaults to box.ROUNDED.
safe_box (bool, optional): Disable box characters that don't display on windows legacy terminal with *raster* fonts. Defaults to True.
expand (bool, optional): IfTrue the panel will stretch to fill the console
width, otherwise it will be sized to fit the contents. Defaults to True.
style (str, optional): The style of the panel (border and contents). Defaults to "none".
border_style (str, optional): The style of the border. Defaults to "none".
width (Optional[int], optional): Optional width of panel. Defaults to None to auto-detect.
height (Optional[int], optional): Optional height of panel. Defaults to None to auto-detect.
padding (Optional[PaddingDimensions]): Optional padding around renderable. Defaults to 0.
highlight (bool, optional): Enable automatic highlighting of panel title (if str). Defaults to False. """
Args:
text (Text): Title or subtitle text.
width (int): Desired width.
align (str): Alignment.
character (str): Character for alignment.
style (Style): Border style
Returns:
Text: New text instance """
text = text.copy()
text.truncate(width)
excess_space = width - cell_len(text.plain) if excess_space: if align == "left": return Text.assemble(
text,
(character * excess_space, style),
no_wrap=True,
end="",
) elif align == "center":
left = excess_space // 2 return Text.assemble(
(character * left, style),
text,
(character * (excess_space - left), style),
no_wrap=True,
end="",
) else: return Text.assemble(
(character * excess_space, style),
text,
no_wrap=True,
end="",
) return text
title_text = self._title if title_text isnotNone:
title_text.stylize_before(border_style)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.