-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfmt.go
53 lines (44 loc) · 1.16 KB
/
fmt.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
package main
import (
"log"
"os"
"github.com/fatih/color"
)
var okColor = color.New(color.FgHiGreen).SprintFunc()
var koColor = color.New(color.FgRed).SprintFunc()
type FmtOutputHandler struct {
Logger *log.Logger
ErrorLogger *log.Logger
Ok string
Ko string
OkColor func(a ...interface{}) string
KoColor func(a ...interface{}) string
PrintContext bool
}
func NewFmtOutputHandler(colored, printContext bool) *FmtOutputHandler {
var olog, elog *log.Logger
if colored {
olog = log.New(os.Stdout, okColor(string("\u2713"+" ")), 0)
elog = log.New(os.Stderr, koColor(string("\u00D7"+" ")), 0)
} else {
olog = log.New(os.Stdout, "", 0)
elog = log.New(os.Stderr, "", 0)
}
return &FmtOutputHandler{
Logger: olog,
ErrorLogger: elog,
PrintContext: printContext,
}
}
func (f *FmtOutputHandler) AddMatches(path string, matches []*Match) {
for _, m := range matches {
if f.PrintContext {
f.Logger.Printf("%v:%v: %v", path, m.LineNumber, m.Content)
} else {
f.Logger.Printf("%v", path)
}
}
}
func (f *FmtOutputHandler) AddPathError(path string, e error) {
f.ErrorLogger.Printf("%v %v\n", path, e.Error())
}