2from typing
import TYPE_CHECKING, Iterable, List
5 from typing
import Literal
10from ._loop
import loop_last
17 """Defines characters to render boxes.
29 box (str): Characters making up box.
30 ascii (bool, optional): True if this box uses ascii characters only. Default is False.
33 def __init__(self, box: str, *, ascii: bool =
False) ->
None:
36 line1, line2, line3, line4, line5, line6, line7, line8 =
box.splitlines()
73 def substitute(self, options:
"ConsoleOptions", safe: bool =
True) ->
"Box":
74 """Substitute this box for another if it won't render due to platform issues.
77 options (ConsoleOptions): Console options used in rendering.
78 safe (bool, optional): Substitute this for another Box if there are known problems
79 displaying on the platform (currently only relevant on Windows). Default is True.
82 Box: A different Box or the same Box.
92 """If this box uses special characters for the borders of the header, then
93 return the equivalent box that does not.
96 Box: The most similar Box that doesn't use header-specific box characters.
97 If the current Box already satisfies this criterion, then it's returned.
101 def get_top(self, widths: Iterable[int]) -> str:
102 """Get the top of a simple box.
105 widths (List[int]): Widths of columns.
108 str: A string of box characters.
111 parts: List[str] = []
114 for last, width
in loop_last(widths):
115 append(self.
top * width)
119 return "".join(parts)
123 widths: Iterable[int],
124 level: Literal[
"head",
"row",
"foot",
"mid"] =
"row",
127 """Get the top of a simple box.
130 width (List[int]): Widths of columns.
133 str: A string of box characters.
150 elif level ==
"foot":
156 raise ValueError(
"level must be 'head', 'row' or 'foot'")
158 parts: List[str] = []
162 for last, width
in loop_last(widths):
163 append(horizontal * width)
168 return "".join(parts)
171 """Get the bottom of a simple box.
174 widths (List[int]): Widths of columns.
177 str: A string of box characters.
180 parts: List[str] = []
183 for last, width
in loop_last(widths):
184 append(self.
bottom * width)
188 return "".join(parts)
219ASCII_DOUBLE_HEAD: Box =
Box(
246SQUARE_DOUBLE_HEAD: Box =
Box(
273MINIMAL_HEAVY_HEAD: Box =
Box(
286MINIMAL_DOUBLE_HEAD: Box =
Box(
447LEGACY_WINDOWS_SUBSTITUTIONS = {
449 MINIMAL_HEAVY_HEAD: MINIMAL,
450 SIMPLE_HEAVY: SIMPLE,
457PLAIN_HEADED_SUBSTITUTIONS = {
459 SQUARE_DOUBLE_HEAD: SQUARE,
460 MINIMAL_DOUBLE_HEAD: MINIMAL,
461 MINIMAL_HEAVY_HEAD: MINIMAL,
462 ASCII_DOUBLE_HEAD: ASCII2,
466if __name__ ==
"__main__":
471 from .
import box
as box
472 from .console
import Console
473 from .table
import Table
474 from .text
import Text
483 "SQUARE_DOUBLE_HEAD",
485 "MINIMAL_HEAVY_HEAD",
486 "MINIMAL_DOUBLE_HEAD",
504 for box_name
in sorted(BOXES):
506 show_footer=
True, style=
"dim", border_style=
"not dim", expand=
True
"Box" substitute(self, "ConsoleOptions" options, bool safe=True)
str get_row(self, Iterable[int] widths, Literal["head", "row", "foot", "mid"] level="row", bool edge=True)
None __init__(self, str box, *bool ascii=False)
str get_bottom(self, Iterable[int] widths)
str get_top(self, Iterable[int] widths)
"Box" get_plain_headed_box(self)