/
quick_use.go
331 lines (269 loc) · 6.7 KB
/
quick_use.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
package color
// There are some funcs for quick start uss.
// type ColoredString string
//
// func (s ColoredString) String() string {
// return string(s)
// }
//
// func (s ColoredString) Print() {
// fmt.Print(s.String())
// }
//
// func (s ColoredString) Println() {
// fmt.Println(s.String())
// }
//
// // Bold use bold
// func Bold(args ...interface{}) ColoredString {
// return ColoredString(OpBold.Render(args...))
// }
// Bold add bold for message
func Bold(args ...interface{}) {
OpBold.Print(args...)
}
// Black add black for message
func Black(args ...interface{}) {
FgBlack.Print(args...)
}
// White add white for message
func White(args ...interface{}) {
FgWhite.Print(args...)
}
// Gray add gray for message
func Gray(args ...interface{}) {
FgDarkGray.Print(args...)
}
// Red add red for message
func Red(args ...interface{}) {
FgRed.Print(args...)
}
// Green add green for message
func Green(args ...interface{}) {
FgGreen.Print(args...)
}
// Yellow add yellow for message
func Yellow(args ...interface{}) {
FgYellow.Print(args...)
}
// Blue add blue for message
func Blue(args ...interface{}) {
FgBlue.Print(args...)
}
// Magenta add magenta for message
func Magenta(args ...interface{}) {
FgMagenta.Print(args...)
}
// Cyan add cyan for message
func Cyan(args ...interface{}) {
FgCyan.Print(args...)
}
/**
print and add new line
*/
// Boldln add bold for message
func Boldln(args ...interface{}) {
OpBold.Println(args...)
}
// Blackln add black for message
func Blackln(args ...interface{}) {
FgBlack.Println(args...)
}
// Whiteln add white for message
func Whiteln(args ...interface{}) {
FgWhite.Println(args...)
}
// Grayln add gray for message
func Grayln(args ...interface{}) {
FgDarkGray.Println(args...)
}
// Redln add red for message
func Redln(args ...interface{}) {
FgRed.Println(args...)
}
// Greenln add green for message
func Greenln(args ...interface{}) {
FgGreen.Println(args...)
}
// Yellowln add yellow for message
func Yellowln(args ...interface{}) {
FgYellow.Println(args...)
}
// Blueln add blue for message
func Blueln(args ...interface{}) {
FgBlue.Println(args...)
}
// Magentaln add magenta for message
func Magentaln(args ...interface{}) {
FgMagenta.Println(args...)
}
// Cyanln add cyan for message
func Cyanln(args ...interface{}) {
FgCyan.Println(args...)
}
// Some defined styles, like bootstrap styles
var BuiltinStyles = map[string]Style{
"info": {OpReset, FgGreen},
"note": {OpBold, FgLightCyan},
"light": {FgLightWhite},
"error": {FgLightWhite, BgRed},
"danger": {OpBold, FgRed},
"notice": {OpBold, FgCyan},
"success": {OpBold, FgGreen},
"comment": {OpReset, FgYellow},
"primary": {OpReset, FgBlue},
"warning": {OpBold, FgYellow},
"question": {OpReset, FgMagenta},
"secondary": {FgDarkGray},
}
// some style name alias
var styleAliases = map[string]string{
"err": "error",
"suc": "success",
"warn": "warning",
}
// AddStyle add a style
func AddStyle(name string, s Style) {
BuiltinStyles[name] = s
}
// GetStyle get style by name
func GetStyle(name string) Style {
if s, ok := BuiltinStyles[name]; ok {
return s
}
if realName, ok := styleAliases[name]; ok {
return BuiltinStyles[realName]
}
// empty style
return New()
}
// GetStyleName
func GetStyleName(name string) string {
if realName, ok := styleAliases[name]; ok {
return realName
}
return name
}
// Suc add suc style for message
func Suc(args ...interface{}) {
GetStyle("success").Print(args...)
}
// Success add success style for message
func Success(args ...interface{}) {
GetStyle("success").Print(args...)
}
// Info add info style for message
func Info(args ...interface{}) {
GetStyle("info").Print(args...)
}
// Secondary add secondary style for message
func Secondary(args ...interface{}) {
GetStyle("secondary").Print(args...)
}
// Comment add comment style for message
func Comment(args ...interface{}) {
GetStyle("comment").Print(args...)
}
// Note add note style for message
func Note(args ...interface{}) {
GetStyle("note").Print(args...)
}
// Notice add notice style for message
func Notice(args ...interface{}) {
GetStyle("notice").Print(args...)
}
// Light add light style for message
func Light(args ...interface{}) {
GetStyle("light").Print(args...)
}
// Warn add warn style for message
func Warn(args ...interface{}) {
GetStyle("warning").Print(args...)
}
// Warning add warning style for message
func Warning(args ...interface{}) {
GetStyle("warning").Print(args...)
}
// Primary add primary style for message
func Primary(args ...interface{}) {
GetStyle("primary").Print(args...)
}
// Danger add danger style for message
func Danger(args ...interface{}) {
GetStyle("danger").Print(args...)
}
// Err add err style for message
func Err(args ...interface{}) {
GetStyle("error").Print(args...)
}
// Error add error style for message
func Error(args ...interface{}) {
GetStyle("error").Print(args...)
}
// Question add question style for message
func Question(args ...interface{}) {
GetStyle("question").Print(args...)
}
/**
print and add new line
*/
// Suc add suc style for message
func Sucln(args ...interface{}) {
GetStyle("success").Println(args...)
}
// Success add success style for message
func Successln(args ...interface{}) {
GetStyle("success").Println(args...)
}
// Info add info style for message
func Infoln(args ...interface{}) {
GetStyle("info").Println(args...)
}
// Secondary add secondary style for message
func Secondaryln(args ...interface{}) {
GetStyle("secondary").Println(args...)
}
// Comment add comment style for message
func Commentln(args ...interface{}) {
GetStyle("comment").Println(args...)
}
// Note add note style for message
func Noteln(args ...interface{}) {
GetStyle("note").Println(args...)
}
// Notice add notice style for message
func Noticeln(args ...interface{}) {
GetStyle("notice").Println(args...)
}
// Light add light style for message
func Lightln(args ...interface{}) {
GetStyle("light").Println(args...)
}
// Warn add warn style for message
func Warnln(args ...interface{}) {
GetStyle("warning").Println(args...)
}
// Warning add warning style for message
func Warningln(args ...interface{}) {
GetStyle("warning").Println(args...)
}
// Primary add primary style for message
func Primaryln(args ...interface{}) {
GetStyle("primary").Println(args...)
}
// Danger add danger style for message
func Dangerln(args ...interface{}) {
GetStyle("danger").Println(args...)
}
// Err add err style for message
func Errln(args ...interface{}) {
GetStyle("error").Println(args...)
}
// Error add error style for message
func Errorln(args ...interface{}) {
GetStyle("error").Println(args...)
}
// Question add question style for message
func Questionln(args ...interface{}) {
GetStyle("question").Println(args...)
}