-
Notifications
You must be signed in to change notification settings - Fork 0
/
styles.go
145 lines (130 loc) · 4.17 KB
/
styles.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright © 2016 Pennock Tech, LLC.
// All rights reserved, except as granted under license.
// Licensed per file LICENSE.txt
package decoration // import "go.pennock.tech/tabular/texttable/decoration"
// The const-style names provide for language error-checking for those who
// explicitly import this package. Both this and just passing a string
// are supported. Package clients are allowed to register their own names,
// for which no const will be available here. Which to use is a trade-off for
// the client to choose.
const (
D_ASCII_SIMPLE = "ascii-simple"
D_NONE = "none"
D_UTF8_LIGHT = "utf8-light"
D_UTF8_LIGHT_CURVED = "utf8-light-curved"
D_UTF8_HEAVY = "utf8-heavy"
D_UTF8_DOUBLE = "utf8-double"
)
// ASCIIBoxSimple provides traditionalist boxes drawn with ASCII characters.
func ASCIIBoxSimple() Decoration {
d := Decoration{
Horizontal: "-",
Vertical: "|",
CrossPiece: "+",
}
d.Populate()
return d
}
func init() { RegisterDecorationName(D_ASCII_SIMPLE, ASCIIBoxSimple()) }
// NoBox ("none") does not draw lines.
func NoBox() Decoration {
d := Decoration{
// isBoxless distinguishes us from the empty decoration error type
isBoxless: true,
}
// Do not populate
return d
}
func init() { RegisterDecorationName(D_NONE, NoBox()) }
// UTF8BoxLight provides boxes drawn from the BOX DRAWINGS LIGHT characters.
func UTF8BoxLight() Decoration {
d := Decoration{
Horizontal: "─",
Vertical: "│",
CrossPiece: "┼",
TopDown: "┬",
BBottomUp: "┴",
TopLeft: "┌",
BottomLeft: "└",
TopRight: "┐",
BottomRight: "┘",
LeftBodyRule: "├",
RightBodyRule: "┤",
}
d.Populate()
return d
}
func init() { RegisterDecorationName(D_UTF8_LIGHT, UTF8BoxLight()) }
// UTF8BoxLightCurved is very similar to UTF8BoxLight but rounds the corners.
func UTF8BoxLightCurved() Decoration {
d := UTF8BoxLight()
d.TopLeft = "╭"
d.BottomLeft = "╰"
d.TopRight = "╮"
d.BottomRight = "╯"
return d
}
func init() { RegisterDecorationName(D_UTF8_LIGHT_CURVED, UTF8BoxLightCurved()) }
// UTF8BoxHeavy provides boxes with a combination of heavy and light lines around borders and rules.
func UTF8BoxHeavy() Decoration {
// ┏━━━┳━━━━━━━┳━━━┓
// ┃ C ┃ Name ┃ N ┃
// ┣━━━╇━━━━━━━╇━━━┫
// ┃ a │ Funky │ 1 ┃
// ┃ b │ Hello │ 2 ┃
// ┠───┼───────┼───┨
// ┃ c │ Final │ 3 ┃
// ┗━━━┷━━━━━━━┷━━━┛
d := Decoration{
Horizontal: "─",
Vertical: "│",
CrossPiece: "┼",
VBorder: "┃",
HOuter: "━",
HTopDown: "┳",
BTopDown: "┯",
BBottomUp: "┷",
TopLeft: "┏",
BottomLeft: "┗",
TopRight: "┓",
BottomRight: "┛",
LeftBodyRule: "┠",
RightBodyRule: "┨",
HBLeft: "┣",
HBCross: "╇",
HBRight: "┫",
}
d.Populate()
return d
}
func init() { RegisterDecorationName(D_UTF8_HEAVY, UTF8BoxHeavy()) }
// There are no "BOX DRAWINGS HEAVY ARC DOWN AND RIGHT" etc characters
// So no UTF8BoxHeavyCurved
// UTF8BoxDouble is similar to UTF8BoxHeavy but uses doubled lines instead of heavy lines.
// Note though that because of a missing character in Unicode, this should probably not be used
// for tables with headers (the interior cross-piece along the header/body boundary will not match up).
func UTF8BoxDouble() Decoration {
d := Decoration{
Horizontal: "─",
Vertical: "│",
CrossPiece: "┼",
VBorder: "║",
HOuter: "═",
HTopDown: "╦",
BTopDown: "╤",
BBottomUp: "╧",
TopLeft: "╔",
BottomLeft: "╚",
TopRight: "╗",
BottomRight: "╝",
LeftBodyRule: "╟",
RightBodyRule: "╢",
HBLeft: "╠",
HBCross: "╪", // BROKEN: Unicode missing "BOX DRAWINGS DOWN SINGLE AND UP HORIZONTAL DOUBLE"?
HBRight: "╣",
// Do the doubling lines really not have an analogy to "BOX DRAWINGS DOWN LIGHT AND UP HORIZONTAL HEAVY"
}
d.Populate()
return d
}
func init() { RegisterDecorationName(D_UTF8_DOUBLE, UTF8BoxDouble()) }