-
Notifications
You must be signed in to change notification settings - Fork 0
/
gocolor.go
58 lines (49 loc) · 1.09 KB
/
gocolor.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
package gocolor
import "fmt"
var colors = map[string]string{
"red": "31",
"green": "32",
"blue": "34",
"yellow": "33",
"magenta": "35",
"gray": "243",
"cyan": "36",
"black": "30",
"white": "37",
"reset": "0",
}
var mode = map[string]string{
"bold": "1",
"italic": "3",
"underline": "4",
"blink": "5",
"strike": "9",
"reset": "0",
}
func ColorizeText(str *string, color, format string) {
inputcheck(&color, &format)
*str = fmt.Sprintf("%s%s%s", color, *str, "\x1b[0;0m")
}
func Colorize(str *string, color, format string) {
inputcheck(&color, &format)
*str = fmt.Sprintf("%s%s", color, *str)
}
func SetColor(color, format string) {
inputcheck(&color, &format)
fmt.Printf(color)
}
func ColorString(str, color, format string ) string {
inputcheck(&color, &format)
return fmt.Sprintf("%s%s%s", color, str, "\x1b[0;0m")
}
func inputcheck(color, format *string) {
*format = mode[*format]
*color = colors[*color]
if *color == "" {
*color = "37"
}
if *format == "" {
*format = "0"
}
*color = fmt.Sprintf("\x1b[%s;%sm", *format, *color)
}