forked from paketo-buildpacks/packit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.go
43 lines (35 loc) · 847 Bytes
/
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
package scribe
import (
"strconv"
)
var (
BlackColor = NewColor(false, 0, -1)
RedColor = NewColor(false, 1, -1)
GreenColor = NewColor(false, 2, -1)
YellowColor = NewColor(false, 3, -1)
BlueColor = NewColor(false, 4, -1)
MagentaColor = NewColor(false, 5, -1)
CyanColor = NewColor(false, 6, -1)
WhiteColor = NewColor(false, 7, -1)
GrayColor = NewColor(false, 244, -1)
)
type Color func(message string) string
func NewColor(bold bool, fg, bg int) Color {
return func(message string) string {
prefix := "\x1b["
if bold {
prefix = prefix + "1"
} else {
prefix = prefix + "0"
}
if fg >= 0 {
prefix = prefix + ";38;5;" + strconv.Itoa(fg)
}
if bg >= 0 {
prefix = prefix + ";48;5;" + strconv.Itoa(bg)
}
prefix = prefix + "m"
suffix := "\x1b[0m"
return prefix + message + suffix
}
}