Handle grep output#774
Conversation
86ee3ea to
5e8c209
Compare
7170f9f to
95f62d2
Compare
2460313 to
8395f5b
Compare
|
If anybody would like to test the |
|
Thanks @zachriggle!
Can you be explicit about what more you'd like to see from delta? One difference I see in your screenshots is that delta is highlighting just the word matches themselves, whereas your script is highlighting the entire line. I'm going to make that possible in delta by exposing styles options. Tentative names: (Or should But beyond that, what else? Did you have in mind the way bat displays ruled margin lines and doesn't repeat the file path in the left margin? |
8395f5b to
7b9958a
Compare
|
Ok, I've pushed the latest to this branch. That includes support for ripgrep Here's my attempt at recreating your example @zachriggle: [delta]
syntax-theme = Solarized (dark)
grep-match-line-style = syntax "#24D7FD"
grep-match-word-style = syntax "#24D7FD"
|
27d5479 to
9614924
Compare
|
One more change @zachriggle: by default it's now going to use I am thinking that this is most useful to users since (a) terminal emulators and other applications often recognize the |
60d1380 to
c2767a5
Compare
|
I don't think I personally have any more TODOs here. If anyone gets a chance to play around with this branch then that would be great, and further suggestions would be very welcome. Otherwise I'll probably release this (and the git blame support) fairly soon. |
|
Thank you @dandavison for implementing this. While playing around with this branch, I noticed that output from some commands other than For example, The colons seem to trigger this. |
Thank you @Kr1ss-XD! |
I pushed a temporary fix, but I wonder whether the real fix is going to involve inspecting the parent process. For example, we could only trigger Alternatively we tighten up the file path regex (how?) that identifies grep lines and be more careful about other situations. For example, |
This could in fact be the more robust way. Catching every possible case with a regex is probably not as trivial as it seems.
I don't have something specific from the top of my head. Although I would imagine that potentially every |
|
Guess I've encountered another bug with this branch. I ran Not sure if this is related to the regex issue, but the empty With the release version of In case it helps : stack backtrace |
fc16f88 to
3a3adc6
Compare
|
Thanks again @Kr1ss-XD for those bugs. I've updated this branch so that delta only attempts to parse input as grep output if either
That change should fix all 3 of the bugs that you encountered. Note that (1) is not guaranteed to work when output from a grep tool is piped to delta, and also that you must use So I'd recommend either:
Both of those should always work. With There are some unit test failures, pending integration of #783. |
3a3adc6 to
43d7c4f
Compare
|
@th1000s if you have a moment would you be able to look at the failures of |
|
This happens because the args set by I suggest abstracting access to that variable and not use |
| { | ||
| determine_calling_process() | ||
| } | ||
| } |
There was a problem hiding this comment.
I suggest abstracting access to that variable and not use
lazy_staticwhen testing.
@th1000s Ah of course (but I bet it would have taken me some time to realise), thanks!
Is this roughly what you had in mind? What would be the right approach for avoiding the clone() here? My first thought was to return Option<Cow<'static, CallingProcess>>, but I'm not sure how to deal with
the trait bound
std::borrow::Cow<'_, _>: std::convert::From<&utils::process::CallingProcess>is not satisfied
There was a problem hiding this comment.
(I'm thinking Cow is the right approach and have the Cow version compiling now)
There was a problem hiding this comment.
Nice, I would have reached for a macro there :)
37b2136 to
cb03c5f
Compare
cb03c5f to
0d541dd
Compare
|
This PR also adds syntax-highlighting for |
2e6fbaa to
e108629
Compare
- Handle standard filepath:code and filepath:line_number:code output as produced by `git grep`, `rg -H`, `grep -H`, etc (with -n for line numbers). - Retain the match highlighting as produced by the grep tool, and expose it in delta's color output styled with grep-match-style. (Note that --color=always is needed to retain the color if piping into delta, but not for `git grep` when delta is configured as git's pager) - Special handling of -p, and -W options of `git grep`: these display the function context in which the matches occur. - `navigate` keybindings jump between match function contexts under `git grep -p` and between matching lines under `git grep -W`. Thanks @zachriggle for the proposal. Fixes #769
e108629 to
eb51193
Compare
Fix broken output for my "gg" (git-grep with option alias) possibly related: dandavison/delta#774









This PR adds the ability to display grep output. Thanks @zachriggle for the proposal! cc @th1000s @Kr1ss-XD
Fixes #769
Handle standard
filepath:codeandfilepath:line_number:codeoutput as produced bygit grep,rg -Hn --color=always,grep -Hn --color=always, etc.Retain the match highlighting as produced by the grep tool, and expose it in delta's color output styled with
grep-match-style. (Note that--color=alwaysis needed to retain the color if piping into delta, but not forgit grepwhen delta is configured as git's pager)grep-match-file-styleandgrep-match-line-number-styleto style thefilepath:line_numberconstruct, similar to thehunk-header-*styles (to which values thegrep-*variants default)Special handling of -p, and -W options of
git grep: these display the function context in which the matches occur.navigatekeybindings jump between match function contexts undergit grep -pand between matching lines undergit grep -W.git grep -nWgit grep -Wshows the entire "function context", including non matching lines. It makes sense to use navigate to jump between matches. Here,navigateis enabled, yielding the bullet markers at the beginning of the lines.git grep -npgit grep -pshows the header of the function context (i.e. the function/class definition, if you're lucky or have configured git's frag detection algorithm well ([1] [2]). Delta re-uses its "hunk header" from git output to display the "function" header in this mode. Therefore ifnavigateis enabled, as here, you can navigate between "functions"rg -Hn --color=alwaysPiped into delta with
grep-match-style = syntax "#444444" grep-match-file-style = cyan grep-match-line-number-style = blue