-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.go
49 lines (40 loc) · 964 Bytes
/
text.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
package log
import "fmt"
type RichText interface {
Format(c Color, bold bool) string
}
type customRichText struct {
implFunc func(c Color, bold bool) string
}
func NewCustomRichText(implFunc func(c Color, bold bool) string) RichText {
return &customRichText{
implFunc: implFunc,
}
}
func (this *customRichText) Format(c Color, bold bool) string {
return this.implFunc(c, bold)
}
type RichString string
func (this RichString) Format(c Color, bold bool) string {
const normalFormat = "\x1b[%dm%s\x1b[0m"
const boldFormat = "\x1b[1;%dm%s\x1b[0m"
var curFmt string
if !bold {
curFmt = normalFormat
} else {
curFmt = boldFormat
}
return fmt.Sprintf(curFmt, uint8(c), this)
}
func (this RichString) logTagFormat(c Color, sp string) string {
return fmt.Sprintf("[%s]%s", this.Format(c, false), sp)
}
type ColorConfig struct {
Debug Color
Info Color
Warn Color
Error Color
Fatal Color
Panic Color
_padding [2]Color
}