-
Notifications
You must be signed in to change notification settings - Fork 1
/
symbols.go
112 lines (92 loc) · 2.59 KB
/
symbols.go
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package tree
import "unicode/utf8"
type Symbols struct {
Connector string
Starter string
Terminator string
Horizontal string
}
func width(s Symbols) int {
co := utf8.RuneCount([]byte(s.Connector))
st := utf8.RuneCount([]byte(s.Starter))
te := utf8.RuneCount([]byte(s.Terminator))
return max(max(co, st), te) + 1
}
// Padding is expected to output a whitespace, or equivalent, used when two nodes
// at the same level are not children to the same parent.
func Padding(style DepthStyler, s Symbols, depth int) string {
return draw(style, " ", width(s), depth)
}
// RenderTerminator is expected to output a terminator marker used for the last node in a list of nodes.
func RenderTerminator(style DepthStyler, s Symbols, depth int) string {
return draw(style, s.Terminator, width(s), depth)
}
// RenderStarter is expected to output the marker used for every node in the tree.
func RenderStarter(style DepthStyler, s Symbols, depth int) string {
return draw(style, s.Starter, width(s), depth)
}
// RenderConnector is expected to output a continuator marker used to connect two nodes
// which are children on the same parent.
func RenderConnector(style DepthStyler, s Symbols, depth int) string {
return draw(style, s.Connector, width(s), depth)
}
// DefaultSymbols returns a set of default Symbols for drawing the tree.
func DefaultSymbols() Symbols {
return normalSymbols
}
var (
normalSymbols = Symbols{
Starter: "├─",
Connector: "│ ",
Terminator: "└─",
}
roundedSymbols = Symbols{
Starter: "├─",
Connector: "│ ",
Terminator: "╰─",
}
thickSymbols = Symbols{
Starter: "┣━",
Connector: "┃ ",
Terminator: "┗━",
}
doubleSymbols = Symbols{
Starter: "╠═",
Connector: "║",
Terminator: "╚═",
}
normalEdgeSymbols = Symbols{
Starter: "╷",
Connector: "│",
Terminator: "╵",
}
thickEdgeSymbols = Symbols{
Starter: "╻",
Connector: "┃",
Terminator: "╹",
}
)
// NormalSymbols returns a standard-type symbols with a normal weight and 90
// degree corners.
func NormalSymbols() Symbols {
return normalSymbols
}
// RoundedSymbols returns a symbols with rounded corners.
func RoundedSymbols() Symbols {
return roundedSymbols
}
// ThickSymbols returns a symbols that's thicker than the one returned by
// NormalSymbols.
func ThickSymbols() Symbols {
return thickSymbols
}
// DoubleSymbols returns a symbols comprised of two thin strokes.
func DoubleSymbols() Symbols {
return doubleSymbols
}
func NormalEdgeSymbols() Symbols {
return normalEdgeSymbols
}
func ThickEdgeSymbols() Symbols {
return thickEdgeSymbols
}