-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexamples_test.go
475 lines (374 loc) · 10.8 KB
/
examples_test.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
package fmtc
// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2024 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //
import (
"fmt"
"os"
"time"
)
// ////////////////////////////////////////////////////////////////////////////////// //
func ExamplePrint() {
// print colored text
// {!} is tag for style reset
Print("{d}black{!}\n")
Print("{r}red{!}\n")
Print("{y}yellow{!}\n")
Print("{b}blue{!}\n")
Print("{c}cyan{!}\n")
Print("{m}magenta{!}\n")
Print("{g}green{!}\n")
Print("{s}light grey{!}\n")
// use text modificators
// light colors
Print("{r-}light red{!}\n")
Print("{r-}dark grey{!}\n")
// bold + color
Print("{r*}red{!}\n")
Print("{g*}green{!}\n")
// dim
Print("{r^}red{!}\n")
Print("{g^}green{!}\n")
// underline
Print("{r_}red{!}\n")
Print("{g_}green{!}\n")
// blink
Print("{r~}red{!}\n")
Print("{g~}green{!}\n")
// reverse
Print("{r@}red{!}\n")
Print("{g@}green{!}\n")
// background color
Print("{D}black{!}\n")
Print("{R}red{!}\n")
Print("{Y}yellow{!}\n")
Print("{B}blue{!}\n")
Print("{C}cyan{!}\n")
Print("{M}magenta{!}\n")
Print("{G}green{!}\n")
Print("{S}light grey{!}\n")
// many tags at once
// underline, cyan text with the red background
Print("{cR_}text{!}\n")
// many tags in once
Print("{r}{*}red and bold{!}\n")
// modificator reset
Print("{r}{*}red and bold {!*}just red{!}\n")
// 256 colors (# for foreground, % for background)
Print("{#201}pink text{!}\n")
Print("{%201}pink background{!}\n")
// 24-bit colors (# for foreground, % for background)
Print("{#7cfc00}lawngreen text{!}\n")
Print("{%6a5acd}slateblue background{!}\n")
// Named colors
// All color names must match the next regex
// pattern: [a-zA-Z0-9_]+
// Add new color with name "error"
NameColor("error", "{r}")
// Print using named color
Print("{?error}lawngreen text{!}\n")
// Redefine "error" color to 24-bit color
NameColor("error", "{#ff0000}")
// Remove named color
RemoveColor("error")
}
func ExamplePrintf() {
// print colored text
// {!} is tag for style reset
Printf("{d}%s{!}\n", "black")
Printf("{r}%s{!}\n", "red")
Printf("{y}%s{!}\n", "yellow")
Printf("{b}%s{!}\n", "blue")
Printf("{c}%s{!}\n", "cyan")
Printf("{m}%s{!}\n", "magenta")
Printf("{g}%s{!}\n", "green")
Printf("{s}%s{!}\n", "light grey")
// use text modificators
// light colors
Printf("{r-}%s{!}\n", "light red")
Printf("{r-}%s{!}\n", "dark grey")
// bold + color
Printf("{r*}%s{!}\n", "red")
Printf("{g*}%s{!}\n", "green")
// dim
Printf("{r^}%s{!}\n", "red")
Printf("{g^}%s{!}\n", "green")
// underline
Printf("{r_}%s{!}\n", "red")
Printf("{g_}%s{!}\n", "green")
// blink
Printf("{r~}%s{!}\n", "red")
Printf("{g~}%s{!}\n", "green")
// reverse
Printf("{r@}%s{!}\n", "red")
Printf("{g@}%s{!}\n", "green")
// background color
Printf("{D}%s{!}\n", "black")
Printf("{R}%s{!}\n", "red")
Printf("{Y}%s{!}\n", "yellow")
Printf("{B}%s{!}\n", "blue")
Printf("{C}%s{!}\n", "cyan")
Printf("{M}%s{!}\n", "magenta")
Printf("{G}%s{!}\n", "green")
Printf("{S}%s{!}\n", "light grey")
// many tags at once
// underline, cyan text with the red background
Printf("{cR_}%s{!}\n", "text")
// many tags in once
Printf("{r}{*}%s{!}\n", "red and bold")
// 256 colors (# for foreground, % for background)
Printf("{#201}%s{!}\n", "pink text")
Printf("{%201}%s{!}\n", "pink background")
// 24-bit colors (# for foreground, % for background)
Printf("{#7cfc00}%s{!}\n", "lawngreen text")
Printf("{%6a5acd}%s{!}\n", "slateblue background")
}
func ExamplePrintfn() {
// print colored text
// {!} is tag for style reset
Printfn("{d}%s{!}", "black")
Printfn("{r}%s{!}", "red")
Printfn("{y}%s{!}", "yellow")
Printfn("{b}%s{!}", "blue")
Printfn("{c}%s{!}", "cyan")
Printfn("{m}%s{!}", "magenta")
Printfn("{g}%s{!}", "green")
Printfn("{s}%s{!}", "light grey")
// use text modificators
// light colors
Printfn("{r-}%s{!}", "light red")
Printfn("{r-}%s{!}", "dark grey")
// bold + color
Printfn("{r*}%s{!}", "red")
Printfn("{g*}%s{!}", "green")
// dim
Printfn("{r^}%s{!}", "red")
Printfn("{g^}%s{!}", "green")
// underline
Printfn("{r_}%s{!}", "red")
Printfn("{g_}%s{!}", "green")
// blink
Printfn("{r~}%s{!}", "red")
Printfn("{g~}%s{!}", "green")
// reverse
Printfn("{r@}%s{!}", "red")
Printfn("{g@}%s{!}", "green")
// background color
Printfn("{D}%s{!}", "black")
Printfn("{R}%s{!}", "red")
Printfn("{Y}%s{!}", "yellow")
Printfn("{B}%s{!}", "blue")
Printfn("{C}%s{!}", "cyan")
Printfn("{M}%s{!}", "magenta")
Printfn("{G}%s{!}", "green")
Printfn("{S}%s{!}", "light grey")
// many tags at once
// underline, cyan text with the red background
Printfn("{cR_}%s{!}", "text")
// many tags in once
Printfn("{r}{*}%s{!}", "red and bold")
// 256 colors (# for foreground, % for background)
Printfn("{#201}%s{!}", "pink text")
Printfn("{%201}%s{!}", "pink background")
// 24-bit colors (# for foreground, % for background)
Printfn("{#7cfc00}%s{!}", "lawngreen text")
Printfn("{%6a5acd}%s{!}", "slateblue background")
}
func ExamplePrintln() {
// print colored text
// {!} is tag for style reset
Println("{d}black{!}")
Println("{r}red{!}")
Println("{y}yellow{!}")
Println("{b}blue{!}")
Println("{c}cyan{!}")
Println("{m}magenta{!}")
Println("{g}green{!}")
Println("{s}light grey{!}")
// use text modificators
// light colors
Println("{r-}light red{!}")
Println("{r-}dark grey{!}")
// bold + color
Println("{r*}red{!}")
Println("{g*}green{!}")
// dim
Println("{r^}red{!}")
Println("{g^}green{!}")
// underline
Println("{r_}red{!}")
Println("{g_}green{!}")
// blink
Println("{r~}red{!}")
Println("{g~}green{!}")
// reverse
Println("{r@}red{!}")
Println("{g@}green{!}")
// background color
Println("{D}black{!}")
Println("{R}red{!}")
Println("{Y}yellow{!}")
Println("{B}blue{!}")
Println("{C}cyan{!}")
Println("{M}magenta{!}")
Println("{G}green{!}")
Println("{S}light grey{!}")
// many tags at once
// underline, cyan text with the red background
Println("{cR_}text{!}")
// many tags in once
Println("{r}{*}red and bold{!}")
// modificator reset
Println("{r}{*}red and bold {!*}just red{!}")
// 256 colors (# for foreground, % for background)
Println("{#201}pink text{!}")
Println("{%201}pink background{!}")
// 24-bit colors (# for foreground, % for background)
Println("{#7cfc00}lawngreen text{!}")
Println("{%6a5acd}slateblue background{!}")
}
func ExampleFprint() {
Fprint(os.Stderr, "{r}This is error message{!}\n")
Fprint(os.Stdout, "{g}This is normal message{!}\n")
}
func ExampleFprintf() {
Fprintf(os.Stderr, "{r}%s{!}\n", "This is error message")
Fprintf(os.Stdout, "{g}%s{!}\n", "This is normal message")
}
func ExampleFprintfn() {
Fprintfn(os.Stderr, "{r}%s{!}", "This is error message")
Fprintfn(os.Stdout, "{g}%s{!}", "This is normal message")
}
func ExampleFprintln() {
Fprintln(os.Stderr, "{r}This is error message{!}")
Fprintln(os.Stdout, "{g}This is normal message{!}")
}
func ExampleSprint() {
msg := Sprint("{r}This is error message{!}\n")
fmt.Print(msg)
}
func ExampleSprintf() {
msg := Sprintf("{r}%s{!}\n", "This is error message")
fmt.Print(msg)
}
func ExampleSprintfn() {
msg := Sprintfn("{r}%s{!}", "This is error message")
fmt.Print(msg)
}
func ExampleSprintln() {
msg := Sprintln("{r}This is error message{!}")
fmt.Print(msg)
}
func ExampleErrorf() {
err := Errorf("This is error")
fmt.Print(err.Error())
}
func ExampleTPrint() {
TPrint("{s}This is temporary text{!}\n")
time.Sleep(time.Second)
TPrint("{*}This message replace previous message after 1 sec{!}\n")
}
func ExampleTPrintf() {
TPrintf("{s}%s{!}\n", "This is temporary text")
time.Sleep(time.Second)
TPrintf("{*}%s{!}\n", "This message replace previous message after 1 sec")
}
func ExampleTPrintln() {
TPrintln("{s}This is temporary text{!}")
time.Sleep(time.Second)
TPrintln("{*}This message replace previous message after 1 sec{!}")
}
func ExampleLPrint() {
// Only "This is text" will be shown
LPrint(12, "{r}This is text {g} with colors{!}")
}
func ExampleLPrintf() {
// Only "This is text" will be shown
LPrintf(12, "{r}This is %s {g} with colors{!}\n", "text")
}
func ExampleLPrintfn() {
// Only "This is text" will be shown
LPrintfn(12, "{r}This is %s {g} with colors{!}", "text")
}
func ExampleLPrintln() {
// Only "This is text" will be shown
LPrintln(12, "{r}This is %s {g} with colors{!}")
}
func ExampleTLPrint() {
// Power of TPrint and LPrint in one method
TLPrint(15, "{s}This is temporary text{!}")
time.Sleep(time.Second)
TLPrint(15, "{*}This message replace previous message after 1 sec{!}")
}
func ExampleTLPrintf() {
// Power of TPrintf and LPrintf in one method
TLPrintf(15, "{s}%s{!}", "This is temporary text")
time.Sleep(time.Second)
TLPrintf(15, "{*}%s{!}", "This message replace previous message after 1 sec")
}
func ExampleTLPrintln() {
// Power of TPrintln and LPrintln in one method
TLPrintln(15, "{s}This is temporary text{!}")
time.Sleep(time.Second)
TLPrintln(15, "{*}This message replace previous message after 1 sec{!}")
}
func ExampleBell() {
// terminal bell
Bell()
}
func ExampleNewLine() {
// just print a new line
NewLine()
// Print 3 new lines
NewLine(3)
}
func ExampleClean() {
// Remove color tags from text
fmt.Println(Clean("{r}Text{!}"))
// Output: Text
}
func ExampleIsColorsSupported() {
fmt.Printf("16 Colors Supported: %t\n", IsColorsSupported())
}
func ExampleIs256ColorsSupported() {
fmt.Printf("256 Colors Supported: %t\n", Is256ColorsSupported())
}
func ExampleIsTrueColorSupported() {
fmt.Printf("TrueColor Supported: %t\n", IsTrueColorSupported())
}
func ExampleIsTag() {
fmt.Printf("%s is tag: %t\n", "{r}", IsTag("{r}"))
fmt.Printf("%s is tag: %t\n", "[r]", IsTag("[r]"))
// Output:
// {r} is tag: true
// [r] is tag: false
}
func ExampleIf() {
userIsAdmin := true
If(userIsAdmin).Println("You are admin!")
}
func ExampleNameColor() {
// Add new color with name "error"
NameColor("error", "{r}")
// Print a message with named color
Print("{?error}lawngreen text{!}\n")
// Redefine "error" color to 24-bit color
NameColor("error", "{#ff0000}")
// Print a message with new color
Print("{?error}lawngreen text{!}\n")
// Create complex named color: pink, italic & underline
NameColor("notice", "{#ff728a}{_}{&}")
// Print a message with complex color
Print("{?notice}lawngreen text{!}\n")
}
func ExampleRemoveColor() {
// Add new color with name "error"
NameColor("error", "{r}")
// Print a message with named color
Print("{?error}lawngreen text{!}\n")
// Remove named color
RemoveColor("error")
}