/
output.go
89 lines (74 loc) · 1.64 KB
/
output.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
80
81
82
83
84
85
86
87
88
89
package head
import (
"fmt"
"strings"
"github.com/fatih/color"
)
const lineSeparator = "\n*********************************************************\n"
// Output collection of dependencies
type Output struct {
color *color.Color
lb bool
}
// NewOutput will return the OutPut
func NewOutput() Output {
return Output{color: color.New(), lb: true}
}
// Error prints error output
func (O *Output) Error(format string, a ...interface{}) {
f, d := color.RedString(format), fmt.Sprint(a...)
fmt.Println(f, d)
}
// Red prints red output
func (O *Output) Red(format string, a ...interface{}) {
if O.lb {
color.Red(format, a...)
return
}
fmt.Print(color.RedString(format))
}
// Green prints green output
func (O *Output) Green(format string, a ...interface{}) {
if O.lb {
color.Green(format, a...)
return
}
fmt.Print(color.GreenString(format))
}
// Blue prints blue output
func (O *Output) Blue(format string, a ...interface{}) {
if O.lb {
color.Cyan(format, a...)
return
}
fmt.Print(color.CyanString(format))
}
// WithLB will ask output to line break
func (O *Output) WithLB() *Output {
O.lb = true
return O
}
// WoutLB will ask output to ignore line break
func (O *Output) WoutLB() *Output {
O.lb = false
return O
}
// Boxes will print map in boxes
func (O *Output) Boxes(s map[string]interface{}) {
for k, v := range s {
l := (80 - len(k)) / 2
if l%2 == 0 {
l--
}
format := strings.Repeat("*", l)
O.Green("\n"+format+" %s "+format, k)
fmt.Println(v)
}
}
// SprintKV will simply print the key-value pair
func (O *Output) SprintKV(
k string,
v interface{}) (o string) {
o += fmt.Sprint(k) + fmt.Sprintln(v)
return o
}