-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformat.go
79 lines (68 loc) · 1.49 KB
/
format.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
package main
import (
"strconv"
"strings"
)
const (
modeFont = 3
modeBackground = 4
modeBrightFont = 9
modeBrightBackground = 10
)
const (
colorBlack = iota
colorRed
colorGreen
colorYellow
colorBlue
colorPurple
colorCyan
colorWhite
)
const (
styleNormal = 0
styleBold = 1
styleFaint = 2
styleItalic = 3
styleUnderline = 4
styleBlink = 5
styleBlinkSlow = 6
styleInvert = 7
styleHidden = 8
styleStrikethrough = 9
styleDoubleUnderline = 21
styleOverline = 53
)
func colored(str string, color, mode, style int) string {
var sb strings.Builder
if style > 0 {
sb.WriteString("\033[")
sb.WriteString(strconv.Itoa(style))
sb.WriteString("m")
}
sb.WriteString("\033[")
sb.WriteString(strconv.Itoa(mode))
sb.WriteString(strconv.Itoa(color))
sb.WriteString("m")
sb.WriteString(str)
sb.WriteString("\033[0m") // reset
return sb.String()
}
func red(str string) string {
return colored(str, colorRed, modeFont, styleNormal)
}
func green(str string) string {
return colored(str, colorGreen, modeFont, styleNormal)
}
func yellow(str string) string {
return colored(str, colorYellow, modeFont, styleNormal)
}
func blue(str string) string {
return colored(str, colorBlue, modeFont, styleNormal)
}
func purple(str string) string {
return colored(str, colorPurple, modeFont, styleNormal)
}
func cyan(str string) string {
return colored(str, colorCyan, modeFont, styleNormal)
}