BurntSushi / ripgrep

ripgrep recursively searches directories for a regex pattern while respecting your gitignore
The Unlicense
48.68k stars 2k forks source link

Different coloring for context lines #1496

Open jaroslawr opened 4 years ago

jaroslawr commented 4 years ago

It would be nice to be able to specify different coloring for context lines - lines that do not contain a match but come from application of -A/-B/-C options, e.g. rg --color nomatchline:fg:gray,line:fg:white. This is possible in vanilla grep like this:

GREP_COLORS="cx=37:" grep -R foo
BurntSushi commented 4 years ago

Can you specify the desired behavior when -v is used and matches in the context lines are highlighted? e.g., This is how ripgrep behaves now:

context-color

In the second example, bar is highlighted as a match even though it is in a non-matching context line.

I guess it looks like grep combines them?

context-color-grep

Not quite sure how I feel about adding yet another color option though. Although I can see how "graying" out the context could lead to a nice effect.

jaroslawr commented 4 years ago

git grep also has the feature in question and has more understandable options than GREP_COLORS, it provides these color settings:

Taking inspiration from this, I think ripgrep could allow to set one or both of new options: matchSelected and matchContext, which when set would take precedence over the match option. Analogously it could allow to set lineSelected and lineContext, taking precedence over line when set.