-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint.go
73 lines (56 loc) · 1.19 KB
/
print.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
package tools
import "fmt"
// 实现输出带颜色字体功能:fmt.Print、fmt.Println
var (
red = "\033[31m"
green = "\033[32m"
blue = "\033[34m"
yellow = "\033[33m"
reset = "\033[0m"
)
// 颜色输出fmt.Print
type PrintColor struct {
text interface{}
}
func Print(text interface{}) PrintColor {
var p PrintColor
p.text = text
return p
}
func (p PrintColor) Red() {
fmt.Print(red, p.text, reset)
}
func (p PrintColor) Green() {
fmt.Print(green, p.text, reset)
}
func (p PrintColor) Blue() {
fmt.Print(blue, p.text, reset)
}
func (p PrintColor) Yellow() {
fmt.Print(yellow, p.text, reset)
}
// 颜色输出fmt.Println,前面会多出一个空格,可以使用fmt.Print("xxx\n")形式处理空格问题
type PrintlnColor struct {
text interface{}
}
func Println(text interface{}) PrintlnColor {
var p PrintlnColor
p.text = text
return p
}
func (p PrintlnColor) Red() {
fmt.Print(red, p.text, reset)
fmt.Print("\n")
}
func (p PrintlnColor) Green() {
fmt.Print(green, p.text, reset)
fmt.Print("\n")
}
func (p PrintlnColor) Blue() {
fmt.Print(blue, p.text, reset)
fmt.Print("\n")
}
func (p PrintlnColor) Yellow() {
fmt.Print(yellow, p.text, reset)
fmt.Print("\n")
}