-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtable_style.go
More file actions
108 lines (92 loc) · 2.32 KB
/
table_style.go
File metadata and controls
108 lines (92 loc) · 2.32 KB
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
package stable
import "errors"
const (
// seperator place holders
_SPHStart string = "S"
_SPHMiddle string = "M"
_SPHEnd string = "E"
_SPHVertical string = "V"
_SPHHorizontal string = "H"
// Border Style Indices
_BSITopLeft int = 0
_BSITopCenter int = 1
_BSITopRight int = 2
_BSIMidLeft int = 3
_BSIMidCenter int = 4
_BSIMidRight int = 5
_BSIBotLeft int = 6
_BSIBotCenter int = 7
_BSIBotRight int = 8
_BSIVertical int = 9
_BSIHorizontal int = 10
)
const (
// BorderStyleDoubleLine double stripped border style
BorderStyleDoubleLine borderStyleName = 1
// BorderStyleSingleLine single stripped border style
BorderStyleSingleLine borderStyleName = 2
// BorderStylePrintableLine printable border style
BorderStylePrintableLine borderStyleName = 3
)
// borderStyleName border style name type
type borderStyleName int
// BorderStyle border style main strcut
type BorderStyle struct {
name borderStyleName
chars [25]string
}
var (
// doubleLine predefined border style
doubleLine *BorderStyle = &BorderStyle{
name: BorderStyleDoubleLine,
chars: [25]string{
"╔", "╦", "╗",
"╠", "╬", "╣",
"╚", "╩", "╝",
"═",
"║",
},
}
// singleLine predefined border style
singleLine *BorderStyle = &BorderStyle{
name: BorderStyleSingleLine,
chars: [25]string{
"┌", "┬", "┐",
"├", "┼", "┤",
"└", "┴", "┘",
"─",
"│",
},
}
// printableLine predefined border style
printableLine *BorderStyle = &BorderStyle{
name: BorderStyleSingleLine,
chars: [25]string{
"+", "-", "+",
"|", "+", "|",
"+", "+", "+",
"-",
"|",
},
}
// DefaultLineStyle default line style
DefaultLineStyle *BorderStyle = printableLine
// all supported styles are mapped with corresponding name *bs pairs
styles map[borderStyleName]*BorderStyle = map[borderStyleName]*BorderStyle{
BorderStyleDoubleLine: doubleLine,
BorderStyleSingleLine: singleLine,
BorderStylePrintableLine: printableLine,
}
)
// get get char value
func (bs *BorderStyle) get(index int) string {
return bs.chars[index]
}
// getStyle get predefined border style
func getStyle(name borderStyleName) (*BorderStyle, error) {
style, exists := styles[name]
if !exists {
return nil, errors.New("stable error. border style not found")
}
return style, nil
}