color.go 919 Bytes
Newer Older
“李磊”'s avatar
“李磊” committed
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
package l

import "fmt"

var color colors

type colors struct{}

// can't use ``
const ansi string = "\x1b[%dm%s\x1b[0m"

const (
	color_red = uint8(iota + 91)
	color_green
	color_yellow
	color_blue
)

func (c *colors) Red(s string) string {
	return fmt.Sprintf(ansi, color_red, s)
}

func (c *colors) Yellow(s string) string {

	return fmt.Sprintf(ansi, color_yellow, s)
}

func (c *colors) Blue(s string) string {

	return fmt.Sprintf(ansi, color_blue, s)
}

func (c *colors) Green(s string) string {

	return fmt.Sprintf(ansi, color_green, s)
}

func (c *colors) autoPaint(level string) string {
	colorLevel := ""
	switch level {
	case "INFO":
		colorLevel = c.Blue(level)
	case "ERROR":
		colorLevel = c.Red(level)
	case "WARN":
		colorLevel = c.Yellow(level)
	case "DEBUG":
		colorLevel = c.Green(level)
	default:
		colorLevel = level
	}
	return colorLevel

}