-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput.go
52 lines (40 loc) · 1.19 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
package main
import (
"fmt"
"io"
)
type Output struct {
stdout io.Writer
verbose bool
}
func (o *Output) reportError(format string, a ...interface{}) {
fmt.Fprintf(o.stdout, "[ERROR] "+format+"\n", a...)
}
func (o *Output) reportInfo(format string, a ...interface{}) {
fmt.Fprintf(o.stdout, "[INFO] "+format+"\n", a...)
}
func (o *Output) reportReplacement(info ReplacementInfo) {
o.print(info.LinesBeforeMatch)
o.print(styleRed(info.MatchLine[:info.MatchLineMatchIndex[0]]))
o.print(styleRedUnderline(info.Match))
o.print(styleRed(info.MatchLine[info.MatchLineMatchIndex[1]:]))
o.print(styleGreen(info.ReplLine[:info.ReplLineReplIndex[0]]))
o.print(styleGreenUnderline(info.Repl))
o.print(styleGreen(info.ReplLine[info.ReplLineReplIndex[1]:]))
o.print(info.LinesAfterMatch)
}
func (o *Output) print(s string) {
fmt.Fprint(o.stdout, s)
}
func (o *Output) printf(format string, a ...interface{}) {
fmt.Fprintf(o.stdout, format, a...)
}
func (o *Output) printHeader(format string, a ...interface{}) {
fmt.Fprintf(o.stdout, styleHeader("\n "+format)+"\n", a...)
}
func (o *Output) reportVerbose(format string, a ...interface{}) {
if !o.verbose {
return
}
o.reportInfo(format, a...)
}