import sys from itertools import chain from typing import TYPE_CHECKING, Iterable, Optional
if sys.version_info >= (3, 8): from typing import Literal else: from pip._vendor.typing_extensions import Literal # pragma: no cover
from .constrain import Constrain from .jupyter import JupyterMixin from .measure import Measurement from .segment import Segment from .style import StyleType
if TYPE_CHECKING: from .console import Console, ConsoleOptions, RenderableType, RenderResult
class Align(JupyterMixin): """Align a renderable by adding spaces if necessary.
Args:
renderable (RenderableType): A console renderable.
align (AlignMethod): One of "left", "center", or"right""
style (StyleType, optional): An optional style to apply to the background.
vertical (Optional[VerticalAlginMethod], optional): Optional vertical align, one of "top", "middle", or"bottom". Defaults to None.
pad (bool, optional): Pad the right with spaces. Defaults to True.
width (int, optional): Restrict contents to given width, orNone to use default width. Defaults to None.
height (int, optional): Set height of align renderable, orNone to fit to contents. Defaults to None.
Raises:
ValueError: if ``align`` isnot one of the expected values. """
def generate_segments() -> Iterable[Segment]: if excess_space <= 0: # Exact fit for line in lines: yieldfrom line yield new_line
elif align == "left": # Pad on the right
pad = Segment(" " * excess_space, style) if self.pad elseNone for line in lines: yieldfrom line if pad: yield pad yield new_line
elif align == "center": # Pad left and right
left = excess_space // 2
pad = Segment(" " * left, style)
pad_right = (
Segment(" " * (excess_space - left), style) if self.pad elseNone
) for line in lines: if left: yield pad yieldfrom line if pad_right: yield pad_right yield new_line
elif align == "right": # Padding on left
pad = Segment(" " * excess_space, style) for line in lines: yield pad yieldfrom line yield new_line
blank_line = (
Segment(f"{' ' * (self.width or options.max_width)}\n", style) if self.pad else Segment("\n")
)
def blank_lines(count: int) -> Iterable[Segment]: if count > 0: for _ in range(count): yield blank_line
def blank_lines(count: int) -> Iterable[Segment]: for _ in range(count): yield blank_line yield new_line
if top_space > 0: yieldfrom blank_lines(top_space) for line in lines: yieldfrom line yield new_line if bottom_space > 0: yieldfrom blank_lines(bottom_space)
if __name__ == "__main__": # pragma: no cover from pip._vendor.rich.console import Console, Group from pip._vendor.rich.highlighter import ReprHighlighter from pip._vendor.rich.panel import Panel
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.