-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor.go
84 lines (71 loc) · 1.71 KB
/
color.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
package logs
import (
"fmt"
"runtime"
)
const (
TextBlack = iota + 30
TextRed
TextGreen
TextYellow
TextBlue
TextMagenta
TextCyan
TextWhite
)
func Black(str string) string {
return textColor(TextBlack, str)
}
func Red(str string) string {
return textColor(TextRed, str)
}
func Green(str string) string {
return textColor(TextGreen, str)
}
func Yellow(str string) string {
return textColor(TextYellow, str)
}
func Blue(str string) string {
return textColor(TextBlue, str)
}
func Magenta(str string) string {
return textColor(TextMagenta, str)
}
func Cyan(str string) string {
return textColor(TextCyan, str)
}
func White(str string) string {
return textColor(TextWhite, str)
}
func textColor(color int, str string) string {
if IsWindows() {
return str
}
switch color {
case TextBlack:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextBlack, str)
case TextRed:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextRed, str)
case TextGreen:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextGreen, str)
case TextYellow:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextYellow, str)
case TextBlue:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextBlue, str)
case TextMagenta:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextMagenta, str)
case TextCyan:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextCyan, str)
case TextWhite:
return fmt.Sprintf("\x1b[0;%dm%s\x1b[0m", TextWhite, str)
default:
return str
}
}
func IsWindows() bool {
if runtime.GOOS == "windows" {
return true
} else {
return false
}
}