Parse filename unambiguously using color escape sequences#1634
Conversation
Rather than indenting the entire body of the function twice, return early if the conditions aren't met.
`git grep`, by default, emits ANSI color escape sequences around the filename, separator, and line number. Parse these if available. This currently assumes the default colors, and will fall back to the previous parsing if any of the colors have been changed. Add tests for filenames that previously failed to parse correctly.
|
Brilliant! This is a great advance. I had switched to using |
|
Hey @joshtriplett, thanks for this. I was also thinking about reading custom Do you plan a follow up pull request for that? |
|
If anyone does work on reading colors from Lines 359 to 366 in dcae5bc |
Parse filename unambiguously using color escape sequences, to handle cases where separators like
-appear in the filename.git grep, by default, emits ANSI color escape sequences around the filename, separator, and line number. Parse these if available.Add tests for filenames that previously failed to parse correctly.
Fixes: #1083
Before:

After:

This currently assumes the default colors, and will fall back to the previous parsing if any of the colors have been changed. This is an issue elsewhere in delta as well; for instance, if
color.grep.matchhas been changed then delta won't highlight matches. I think this would be easy to fix, by parsing git's color configuration (which I implemented inanstyle-git), rendering those color sequences to ANSI escapes, and using those in the regex rather than hardcoded ones. However, I think that should be a separate PR.