-
Notifications
You must be signed in to change notification settings - Fork 14
/
summary.go
38 lines (34 loc) · 1.01 KB
/
summary.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
package helpers
import (
"bytes"
"fmt"
"io"
"os"
"rare/pkg/color"
"rare/pkg/extractor"
"rare/pkg/humanize"
)
func FWriteMatchSummary(w io.Writer, matched, total uint64) {
fmt.Fprintf(w, "Matched: %s / %s",
color.Wrapi(color.BrightGreen, humanize.Hui(matched)),
color.Wrapi(color.BrightWhite, humanize.Hui(total)))
}
func FWriteExtractorSummary(extractor *extractor.Extractor, errors uint64, additionalParts ...string) string {
var w bytes.Buffer
FWriteMatchSummary(&w, extractor.MatchedLines(), extractor.ReadLines())
for _, p := range additionalParts {
w.WriteRune(' ')
w.WriteString(p)
}
if extractor.IgnoredLines() > 0 {
fmt.Fprintf(&w, " (Ignored: %s)", color.Wrapi(color.Red, humanize.Hui(extractor.IgnoredLines())))
}
if errors > 0 {
fmt.Fprintf(&w, " %s", color.Wrapf(color.Red, "(Errors: %v)", humanize.Hui(errors)))
}
return w.String()
}
func WriteExtractorSummary(extractor *extractor.Extractor) {
os.Stderr.WriteString(FWriteExtractorSummary(extractor, 0))
os.Stderr.WriteString("\n")
}