Воркед

This commit is contained in:
kromskii2 committed 2025-03-15 09:36:28 +07:00
1 parent ac32c55ab9
commit ee94d8e529
1138 files changed
+55771 -77901

No files matched your search

+16 -10
View File
@@ -8,18 +8,32 @@ from .segment import Segment
from .style import Style, StyleStack, StyleType
from .styled import Styled
GuideType = Tuple[str, str, str, str]
class Tree(JupyterMixin):
"""A renderable for a tree structure.
Attributes:
ASCII_GUIDES (GuideType): Guide lines used when Console.ascii_only is True.
TREE_GUIDES (List[GuideType, GuideType, GuideType]): Default guide lines.
Args:
label (RenderableType): The renderable or str for the tree label.
style (StyleType, optional): Style of this tree. Defaults to "tree".
guide_style (StyleType, optional): Style of the guide lines. Defaults to "tree.line".
expanded (bool, optional): Also display children. Defaults to True.
highlight (bool, optional): Highlight renderable (if str). Defaults to False.
hide_root (bool, optional): Hide the root node. Defaults to False.
"""
ASCII_GUIDES = (" ", "| ", "+-- ", "`-- ")
TREE_GUIDES = [
(" ", "│ ", "├── ", "└── "),
(" ", "┃ ", "┣━━ ", "┗━━ "),
(" ", "║ ", "╠══ ", "╚══ "),
]
def __init__(
self,
label: RenderableType,
@@ -72,7 +86,6 @@ class Tree(JupyterMixin):
def __rich_console__(
self, console: "Console", options: "ConsoleOptions"
) -> "RenderResult":
stack: List[Iterator[Tuple[bool, Tree]]] = []
pop = stack.pop
push = stack.append
@@ -83,21 +96,15 @@ class Tree(JupyterMixin):
guide_style = get_style(self.guide_style, default="") or null_style
SPACE, CONTINUE, FORK, END = range(4)
ASCII_GUIDES = (" ", "| ", "+-- ", "`-- ")
TREE_GUIDES = [
(" ", "│ ", "├── ", "└── "),
(" ", "┃ ", "┣━━ ", "┗━━ "),
(" ", "║ ", "╠══ ", "╚══ "),
]
_Segment = Segment
def make_guide(index: int, style: Style) -> Segment:
"""Make a Segment for a level of the guide lines."""
if options.ascii_only:
line = ASCII_GUIDES[index]
line = self.ASCII_GUIDES[index]
else:
guide = 1 if style.bold else (2 if style.underline2 else 0)
line = TREE_GUIDES[0 if options.legacy_windows else guide][index]
line = self.TREE_GUIDES[0 if options.legacy_windows else guide][index]
return _Segment(line, style)
levels: List[Segment] = [make_guide(CONTINUE, guide_style)]
@@ -195,7 +202,6 @@ class Tree(JupyterMixin):
if __name__ == "__main__": # pragma: no cover
from pip._vendor.rich.console import Group
from pip._vendor.rich.markdown import Markdown
from pip._vendor.rich.panel import Panel