8
8
from .style import Style , StyleStack , StyleType
9
9
from .styled import Styled
10
10
11
+ GuideType = Tuple [str , str , str , str ]
11
12
12
13
class Tree (JupyterMixin ):
13
14
"""A renderable for a tree structure.
14
15
16
+ Attributes:
17
+ ASCII_GUIDES (GuideType): Guide lines used when Console.ascii_only is True.
18
+ TREE_GUIDES (List[GuideType, GuideType, GuideType]): Default guide lines.
19
+
15
20
Args:
16
21
label (RenderableType): The renderable or str for the tree label.
17
22
style (StyleType, optional): Style of this tree. Defaults to "tree".
@@ -21,6 +26,13 @@ class Tree(JupyterMixin):
21
26
hide_root (bool, optional): Hide the root node. Defaults to False.
22
27
"""
23
28
29
+ ASCII_GUIDES = (" " , "| " , "+-- " , "`-- " )
30
+ TREE_GUIDES = [
31
+ (" " , "│ " , "├── " , "└── " ),
32
+ (" " , "┃ " , "┣━━ " , "┗━━ " ),
33
+ (" " , "║ " , "╠══ " , "╚══ " ),
34
+ ]
35
+
24
36
def __init__ (
25
37
self ,
26
38
label : RenderableType ,
@@ -83,21 +95,15 @@ def __rich_console__(
83
95
guide_style = get_style (self .guide_style , default = "" ) or null_style
84
96
SPACE , CONTINUE , FORK , END = range (4 )
85
97
86
- ASCII_GUIDES = (" " , "| " , "+-- " , "`-- " )
87
- TREE_GUIDES = [
88
- (" " , "│ " , "├── " , "└── " ),
89
- (" " , "┃ " , "┣━━ " , "┗━━ " ),
90
- (" " , "║ " , "╠══ " , "╚══ " ),
91
- ]
92
98
_Segment = Segment
93
99
94
100
def make_guide (index : int , style : Style ) -> Segment :
95
101
"""Make a Segment for a level of the guide lines."""
96
102
if options .ascii_only :
97
- line = ASCII_GUIDES [index ]
103
+ line = self . ASCII_GUIDES [index ]
98
104
else :
99
105
guide = 1 if style .bold else (2 if style .underline2 else 0 )
100
- line = TREE_GUIDES [0 if options .legacy_windows else guide ][index ]
106
+ line = self . TREE_GUIDES [0 if options .legacy_windows else guide ][index ]
101
107
return _Segment (line , style )
102
108
103
109
levels : List [Segment ] = [make_guide (CONTINUE , guide_style )]
0 commit comments