MCPcopy
hub / github.com/Textualize/rich / Tree

Class Tree

rich/tree.py:14–201  ·  rich/tree.py::Tree

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 labe

Source from the content-addressed store, hash-verified

12
13
14class Tree(JupyterMixin):
15 class="st">"""A renderable for a tree structure.
16
17 Attributes:
18 ASCII_GUIDES (GuideType): Guide lines used when Console.ascii_only is True.
19 TREE_GUIDES (List[GuideType, GuideType, GuideType]): Default guide lines.
20
21 Args:
22 label (RenderableType): The renderable or str for the tree label.
23 style (StyleType, optional): Style of this tree. Defaults to class="st">"tree".
24 guide_style (StyleType, optional): Style of the guide lines. Defaults to class="st">"tree.line".
25 expanded (bool, optional): Also display children. Defaults to True.
26 highlight (bool, optional): Highlight renderable (if str). Defaults to False.
27 hide_root (bool, optional): Hide the root node. Defaults to False.
28 class="st">"""
29
30 ASCII_GUIDES = (class="st">" ", class="st">"| ", class="st">"+-- ", class="st">"`-- ")
31 TREE_GUIDES = [
32 (class="st">" ", class="st">"│ ", class="st">"├── ", class="st">"└── "),
33 (class="st">" ", class="st">"┃ ", class="st">"┣━━ ", class="st">"┗━━ "),
34 (class="st">" ", class="st">"║ ", class="st">"╠══ ", class="st">"╚══ "),
35 ]
36
37 def __init__(
38 self,
39 label: RenderableType,
40 *,
41 style: StyleType = class="st">"tree",
42 guide_style: StyleType = class="st">"tree.line",
43 expanded: bool = True,
44 highlight: bool = False,
45 hide_root: bool = False,
46 ) -> None:
47 self.label = label
48 self.style = style
49 self.guide_style = guide_style
50 self.children: List[Tree] = []
51 self.expanded = expanded
52 self.highlight = highlight
53 self.hide_root = hide_root
54
55 def add(
56 self,
57 label: RenderableType,
58 *,
59 style: Optional[StyleType] = None,
60 guide_style: Optional[StyleType] = None,
61 expanded: bool = True,
62 highlight: Optional[bool] = False,
63 ) -> class="st">"Tree":
64 class="st">"""Add a child tree.
65
66 Args:
67 label (RenderableType): The renderable or str for the tree label.
68 style (StyleType, optional): Style of this tree. Defaults to class="st">"tree".
69 guide_style (StyleType, optional): Style of the guide lines. Defaults to class="st">"tree.line".
70 expanded (bool, optional): Also display children. Defaults to True.
71 highlight (Optional[bool], optional): Highlight renderable (if str). Defaults to False.

Callers 13

test_render_single_nodeFunction · 0.90
test_render_asciiFunction · 0.90
test_render_tree_win32Function · 0.90
test_tree_measureFunction · 0.90
tree.pyFile · 0.90
treeMethod · 0.90
addMethod · 0.85

Calls

no outgoing calls

Tested by 9

test_render_single_nodeFunction · 0.72
test_render_asciiFunction · 0.72
test_render_tree_win32Function · 0.72
test_tree_measureFunction · 0.72