Skip to content

Commit

Permalink
Merge pull request #8 from bayashi/highlight-matched-line-number
Browse files Browse the repository at this point in the history
highlight matched line number
  • Loading branch information
bayashi authored Mar 4, 2024
2 parents b2ceea6 + 95f9f2c commit d249fb6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions xfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ type path struct {
type xfg struct {
options *options

pathHighlighter string
grepHighlighter string
pathHighlitColor *color.Color
pathHighlighter string
grepHighlitColor *color.Color
grepHighlighter string

result []path
}
Expand All @@ -37,9 +39,11 @@ func NewX(o *options, pathHighlightColor *color.Color, grepHighlightColor *color
options: o,
}
if pathHighlightColor != nil {
x.pathHighlitColor = pathHighlightColor
x.pathHighlighter = pathHighlightColor.Sprintf(x.options.searchPath)
}
if grepHighlightColor != nil {
x.grepHighlitColor = grepHighlightColor
x.grepHighlighter = grepHighlightColor.Sprintf(x.options.searchGrep)
}

Expand All @@ -52,7 +56,11 @@ func (x *xfg) Show(w io.Writer) error {
return err
}
for _, line := range p.content {
if _, err := fmt.Fprintf(w, " %d: %s\n", line.lc, line.content); err != nil {
lc := fmt.Sprintf("%d", line.lc)
if !x.options.noColor && line.matched {
lc = x.grepHighlitColor.Sprint(lc)
}
if _, err := fmt.Fprintf(w, " %s: %s\n", lc, line.content); err != nil {
return err
}
}
Expand Down

0 comments on commit d249fb6

Please sign in to comment.