def substitute(self, options: "ConsoleOptions", safe: bool = True) -> "Box": """Substitute this box for another if it won't render due to platform issues.
Args:
options (ConsoleOptions): Console options used in rendering.
safe (bool, optional): Substitute this for another Box if there are known problems
displaying on the platform (currently only relevant on Windows). Default isTrue.
Returns:
Box: A different Box or the same Box. """
box = self if options.legacy_windows and safe:
box = LEGACY_WINDOWS_SUBSTITUTIONS.get(box, box) if options.ascii_only andnot box.ascii:
box = ASCII return box
def get_plain_headed_box(self) -> "Box": """If this box uses special characters for the borders of the header, then return the equivalent box that does not.
Returns:
Box: The most similar Box that doesn't use header-specific box characters. If the current Box already satisfies this criterion, then it's returned. """ return PLAIN_HEADED_SUBSTITUTIONS.get(self, self)
def get_top(self, widths: Iterable[int]) -> str: """Get the top of a simple box.
Args:
widths (List[int]): Widths of columns.
Returns:
str: A string of box characters. """
parts: List[str] = []
append = parts.append
append(self.top_left) for last, width in loop_last(widths):
append(self.top * width) ifnot last:
append(self.top_divider)
append(self.top_right) return"".join(parts)
def get_row(
self,
widths: Iterable[int],
level: Literal["head", "row", "foot", "mid"] = "row",
edge: bool = True,
) -> str: """Get the top of a simple box.
Args:
width (List[int]): Widths of columns.
Returns:
str: A string of box characters. """ if level == "head":
left = self.head_row_left
horizontal = self.head_row_horizontal
cross = self.head_row_cross
right = self.head_row_right elif level == "row":
left = self.row_left
horizontal = self.row_horizontal
cross = self.row_cross
right = self.row_right elif level == "mid":
left = self.mid_left
horizontal = " "
cross = self.mid_vertical
right = self.mid_right elif level == "foot":
left = self.foot_row_left
horizontal = self.foot_row_horizontal
cross = self.foot_row_cross
right = self.foot_row_right else: raise ValueError("level must be 'head', 'row' or 'foot'")
parts: List[str] = []
append = parts.append if edge:
append(left) for last, width in loop_last(widths):
append(horizontal * width) ifnot last:
append(cross) if edge:
append(right) return"".join(parts)
def get_bottom(self, widths: Iterable[int]) -> str: """Get the bottom of a simple box.
Args:
widths (List[int]): Widths of columns.
Returns:
str: A string of box characters. """
parts: List[str] = []
append = parts.append
append(self.bottom_left) for last, width in loop_last(widths):
append(self.bottom * width) ifnot last:
append(self.bottom_divider)
append(self.bottom_right) return"".join(parts)
# Map Boxes that don't render with raster fonts on to equivalent that do
LEGACY_WINDOWS_SUBSTITUTIONS = {
ROUNDED: SQUARE,
MINIMAL_HEAVY_HEAD: MINIMAL,
SIMPLE_HEAVY: SIMPLE,
HEAVY: SQUARE,
HEAVY_EDGE: SQUARE,
HEAVY_HEAD: SQUARE,
}
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.