dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
21.34k stars 359 forks source link

🐛 Delta doesn't highlight matches if `color.grep.match` changed #1635

Open joshtriplett opened 4 months ago

joshtriplett commented 4 months ago

If the user's git configuration customizes color.grep.match, delta won't recognize and highlight matches.

For instance, here's git grep 'Get Started' in the delta repository with my configuration, which sets color.grep.match = 'bold green':

image

Here's the same grep with the default git grep color configuration:

image

Here's the raw text output as a hexdump (using -c color.pager=hd) in both cases:

With color.grep.match = 'bold green':

00000000  1b 5b 33 35 6d 52 45 41  44 4d 45 2e 6d 64 1b 5b  |.[35mREADME.md.[|
00000010  6d 1b 5b 33 36 6d 3a 1b  5b 6d 23 23 20 1b 5b 31  |m.[36m:.[m## .[1|
00000020  3b 33 32 6d 47 65 74 20  53 74 61 72 74 65 64 1b  |;32mGet Started.|
00000030  5b 6d 0a                                          |[m.|
00000033

With the default color.grep.match = 'bold red':

00000000  1b 5b 33 35 6d 52 45 41  44 4d 45 2e 6d 64 1b 5b  |.[35mREADME.md.[|
00000010  6d 1b 5b 33 36 6d 3a 1b  5b 6d 23 23 20 1b 5b 31  |m.[36m:.[m## .[1|
00000020  3b 33 31 6d 47 65 74 20  53 74 61 72 74 65 64 1b  |;31mGet Started.|
00000030  5b 6d 0a                                          |[m.|
00000033

Note the different color code on the ANSI escape right before the match.

I think the most obvious way to fix this would be to retrieve and parse git's color configuration (e.g. using something like anstyle-git), render the result as an ANSI escape sequence, and match against that.

Thanks for filing a Delta bug report!