-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxfg.go
66 lines (55 loc) · 1.11 KB
/
xfg.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
package main
import (
"io/fs"
"regexp"
"sync"
"github.com/fatih/color"
)
type line struct {
lc int32 // line number
content string
matched bool
}
type path struct {
path string
info fs.DirEntry
contents []line
}
type result struct {
mu sync.RWMutex
paths []path
outputLC int // Used on pager. Rough count. Not included group separators.
alreadyMatchContent bool
}
type highlighter struct {
pathBaseColor string
pathHighlightColor *color.Color
pathHighlighter []string
grepHighlightColor *color.Color
grepHighlighter []string
}
type xfgExtra struct {
searchPathi []*regexp.Regexp
searchGrepi []*regexp.Regexp
searchPathRe []*regexp.Regexp
searchGrepRe []*regexp.Regexp
ignoreOptionRe []*regexp.Regexp
}
type xfg struct {
cli *runner
options *options
highlighter highlighter
extra xfgExtra
result result
}
func newX(cli *runner, o *options) *xfg {
o.prepareFromENV()
o.prepareAliases()
o.prepareContextLines(cli.isTTY)
o.prepareRuntimeFlags()
x := &xfg{
cli: cli,
options: o,
}
return x
}