-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolterm.go
142 lines (116 loc) · 3.04 KB
/
colterm.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
package main
import "fmt"
/*
Black 30 40
Red 31 41
Green 32 42
Yellow 33 43
Blue 34 44
Magenta 35 45
Cyan 36 46
White 37 47
Option Code Description
Reset
0 Back to normal (remove all styles)
Bold
1 Bold the text
Underline
4 Underline text
Inverse
7 Interchange colors of background and foreground
Bold off
21 Normal from bold
Underline off
24 Normal from Underline
Inverse off
27 Reverse of the Inverse
*/
var Black, Red, Green, Yellow, Blue, Magenta, Cyan, White string
var Colors = []*string{&Black, &Red, &Green, &Yellow, &Blue, &Magenta, &Cyan, &White}
var Reset, Bold, Dim, Script, Underline, X5, X6, Swap string
var Specials = []*string{&Reset, &Bold, &Dim, &Script, &Underline, &X5, &X6, &Swap}
const SpeciallOff = 20
const font = 30
const backg = 40
const esc = "\033["
const reset = esc + "0m"
func CFormat(msg string, color, special *string) (cmsg string) {
spec := ""
for i := 0; i < len(Specials); i++ {
if Specials[i] == special {
spec = fmt.Sprint(i)
}
}
cmsg = msg
for i, c := range Colors {
if c == color {
ci := font + i
cmsg = esc + spec + ";" + fmt.Sprintf("%vm", ci) + cmsg + reset
}
}
return
}
// Red
func RedIt(om string, a ...any) string {
return CFormat(fmt.Sprintf(om, a...), &Red, nil)
}
// Red bold
func RedBIt(om string, a ...any) string {
return CFormat(fmt.Sprintf(om, a...), &Red, &Bold)
}
// Green
func GreenIt(om string, a ...any) string {
return CFormat(fmt.Sprintf(om, a...), &Green, nil)
}
// Green bold
func GreenBIt(om string, a ...any) string {
return CFormat(fmt.Sprintf(om, a...), &Green, &Bold)
}
// Black
func BlackIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Black, nil)
}
// Black bold
func BlackBIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Black, &Bold)
}
// Yellow
func YellowIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Yellow, nil)
}
// Yellow bold
func YellowBIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Yellow, &Bold)
}
// Blue
func BlueIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Blue, nil)
}
// Blue bold
func BlueBIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Blue, &Bold)
}
// Magenta
func MagentaIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Magenta, nil)
}
// Magenta bold
func MagentaBIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Magenta, &Bold)
}
// Cyan
func CyanIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Cyan, nil)
}
// Cyan bold
func CyanBIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &Cyan, &Bold)
}
// White
func WhiteIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &White, nil)
}
// White bold
func WhiteBIt(format string, a ...interface{}) string {
return CFormat(fmt.Sprintf(format, a...), &White, &Bold)
}