-
Notifications
You must be signed in to change notification settings - Fork 12
/
report-tools.go
142 lines (115 loc) · 3.23 KB
/
report-tools.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package nexus_compare
// This part is a fork of lib https://github.com/homeport/dyff
import (
"fmt"
"github.com/gonvenience/bunt"
"github.com/gonvenience/neat"
"github.com/gonvenience/ytbx"
"github.com/lucasb-eyer/go-colorful"
)
var (
additionGreen = color("#58BF38")
modificationYellow = color("#C7C43F")
removalRed = color("#B9311B")
)
func yamlStringInGreenishColors(input interface{}) (string, error) {
return neat.NewOutputProcessor(true, true, &map[string]colorful.Color{
"keyColor": bunt.Green,
"indentLineColor": {R: 0, G: 0.2, B: 0},
"scalarDefaultColor": bunt.LimeGreen,
"boolColor": bunt.LimeGreen,
"floatColor": bunt.LimeGreen,
"intColor": bunt.LimeGreen,
"multiLineTextColor": bunt.OliveDrab,
"nullColor": bunt.Olive,
"emptyStructures": bunt.DarkOliveGreen,
"dashColor": bunt.Green,
}).ToYAML(input)
}
func yamlStringInRedishColors(input interface{}) (string, error) {
return neat.NewOutputProcessor(true, true, &map[string]colorful.Color{
"keyColor": bunt.FireBrick,
"indentLineColor": {R: 0.2, G: 0, B: 0},
"scalarDefaultColor": bunt.LightCoral,
"boolColor": bunt.LightCoral,
"floatColor": bunt.LightCoral,
"intColor": bunt.LightCoral,
"multiLineTextColor": bunt.DarkSalmon,
"nullColor": bunt.Salmon,
"emptyStructures": bunt.LightSalmon,
"dashColor": bunt.FireBrick,
}).ToYAML(input)
}
func colored(color colorful.Color, format string, a ...interface{}) string {
return bunt.Style(
render(format, a...),
bunt.EachLine(),
bunt.Foreground(color),
)
}
func color(hex string) colorful.Color {
color, _ := colorful.Hex(hex)
return color
}
func render(format string, a ...interface{}) string {
if len(a) == 0 {
return format
}
return fmt.Sprintf(format, a...)
}
func green(format string, a ...interface{}) string {
return colored(additionGreen, render(format, a...))
}
func red(format string, a ...interface{}) string {
return colored(removalRed, render(format, a...))
}
func yellow(format string, a ...interface{}) string {
return colored(modificationYellow, render(format, a...))
}
func lightgreen(format string, a ...interface{}) string {
return colored(bunt.LightGreen, render(format, a...))
}
func lightred(format string, a ...interface{}) string {
return colored(bunt.LightSalmon, render(format, a...))
}
func dimgray(format string, a ...interface{}) string {
return colored(bunt.DimGray, render(format, a...))
}
func bold(format string, a ...interface{}) string {
return bunt.Style(
fmt.Sprintf(format, a...),
bunt.EachLine(),
bunt.Bold(),
)
}
func italic(format string, a ...interface{}) string {
return bunt.Style(
render(format, a...),
bunt.EachLine(),
bunt.Italic(),
)
}
func pathToString(path *ytbx.Path, useGoPatchPaths bool, showPathRoot bool) string {
var result string
if useGoPatchPaths {
result = styledGoPatchPath(path)
} else {
result = styledDotStylePath(path)
}
if path != nil && showPathRoot {
result += bunt.Sprintf(" LightSteelBlue{(%s)}", path.RootDescription())
}
return result
}
func max(a, b int) int {
if a > b {
return a
}
return b
}
func min(a, b int) int {
if a < b {
return a
}
return b
}