-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathexample.py
46 lines (39 loc) · 1.17 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from collections import OrderedDict as OD
from copy import deepcopy
from asciitree import LeftAligned
from asciitree.drawing import BoxStyle, BOX_DOUBLE, BOX_BLANK
tr = LeftAligned()
# a basic tree
# OrderedDict is used in some places where node order is important, otherwise
# a normal dict is used for the sake of readabilitiy
tree = {
'asciitree': OD([
('sometimes',
{'you': {}}),
('just',
{'want': OD([
('to', {}),
('draw', {}),
])}),
('trees', {}),
('in', {
'your': {
'terminal': {}
}
})
])
}
print(tr(tree))
# construct a more complex tree by copying the tree and grafting it onto itself
tree2 = deepcopy(tree)
tree2['asciitree']['trees'] = deepcopy(tree2['asciitree'])
print(tr(tree2))
# use a box style
box_tr = LeftAligned(draw=BoxStyle(gfx=BOX_DOUBLE, horiz_len=1))
print(box_tr(tree))
# more airy
air_tr = LeftAligned(draw=BoxStyle(gfx=BOX_BLANK,
label_space=0,
label_format='[{}]',
indent=0))
print(air_tr(tree))