Delta[0] applies syntax highlighting to the code sections of git and diff output, and uses background colors (instead of +/-) to indicate added / removed content. It's written in Rust, and uses the syntect[1] highlighting library. That's the same library that bat[2] uses, so delta supports all the same color themes, and any bat configuration that you already have in place (environment variables, custom themes/language support) is automatically honored by delta. Delta also infers and highlights substrings that differ between lines (similar to Github, Gitlab and other diff viewers) and optionally cleans up the raw diff output slightly to make it more human readable.
Yes it does. Thanks for asking, I hadn't tested this out. The key is the `--color-only` argument, which guarantees that, other than ANSI color escape sequences, the original output from git is unchanged:
Looks like it works 'properly' in the sense that it does all that it can (colouring, incl. syntax highlighting, which d-s-f never does) without making the result wonky.
The core issue is the same for delta as it is for d-s-f (or any other interactive pager) - there must be a 1:1 correspondence between lines out from git, and lines back into it.
So, delta can do the fancier colouring interactively, but it can't mess with the header either, for the same underlying reason. (And so 'solved' it with a `--color-only` flag.)
This might be just me but looking at the screenshots, I clearly prefer the GitHub one as it shows the line numbers of every line in both before and after. Line numbers make jumping between the diff and the editor fast and efficient.
Thanks, that's definitely a feature that could be added. My original thought was that the line numbers in the after file are nearly always what one wants, since that's the version that your editor will most naturally be displaying. And I wanted to reduce visual clutter. Delta currently displays just the first line number of each diff hunk; not on every line. But that's also something that could be made configurable.
Ideally, I think that a mouse click in an appropriate location in a terminal emulator window should open the user's editor on the correct line of the correct file.
As a suggestion, I'd have the configuration step in 'Configure git to use delta' not reference a theme that doesn't come with the initial install as you've done with 'base-16.ocean.dark'. I had to investigate why, and (admittedly happily) then found out about bat and installed that and changed it to 'zenburn'. But I suppose most users would like to see it work without having to do that.
I don't know if this is better per-se but my diff-so-fancy config sat in [pager] rather than [core]. I verified that git-delta works as configured this way instead:
Thanks. I like the light theme also. If anyone has suggestions of good {theme, background-highlight-colors} choices, especially for dark backgrounds, please open a PR/issue and we can add them to the README.
This is neat. In a similar fashion I'm a big fan of diff-highlight, [0] which post-processes the git diff and highlights with color the differing segments. It's super lightweight and part of the official git repo; I've saved it as a standalone #!/bin/perl in my $PATH and then included it in my .gitconfig:
[pager]
log = /Users/user/.bin/diff-highlight | less
show = /Users/user/.bin/diff-highlight | less
diff = /Users/user/.bin/diff-highlight | less
This does look nice, though I'm a little confused by the choice to highlight the section below the function declaration change even though it doesnt appear to have a change.
Is it the hunk header you're referring to? That's something that git outputs, like this, before the diff hunk:
@@ -62,17 +62,17 @@ class MyClass:
Delta makes that more prominent by surrounding it with a box (by default) and getting rid of the for-machines characters that git puts there. It doesn't apply background colors to it though: delta only applies background red and green shading to removed/added lines.
(I believe that one can customize the regular expressions that git uses to decide on the hunk header; they're sometimes appropriate and sometimes not, for the languages that I use.)
Not sure about vim-fugitive, but vim-gitgutter's hunk previews have intra-line highlighting. I mention it because people often use the two plugins together (and I'm pleased with how vgg's highlighting turned out :)
⟩ git diff
error: Found argument 'Extended' which wasn't expected, or isn't valid in this context
USAGE:
delta --dark --minus-color <minus_color> --plus-color <plus_color> --theme <theme>
For more information try --help
My ~/.gitconfig file has the copy pasted lines from the github example
I agree. If anyone has nice combinations of delta background colors and syntax highlighting theme for dark backgrounds, please send them my way! (Here, or PR/issue).
41 comments
[ 2.5 ms ] story [ 78.1 ms ] thread[0] https://github.com/dandavison/delta
[1] https://github.com/trishume/syntect
[2] http://github.com/sharkdp/bat/
The core issue is the same for delta as it is for d-s-f (or any other interactive pager) - there must be a 1:1 correspondence between lines out from git, and lines back into it.
So, delta can do the fancier colouring interactively, but it can't mess with the header either, for the same underlying reason. (And so 'solved' it with a `--color-only` flag.)
https://diff2html.xyz/
npm-installed cli which shows you git diff in your browser
EDIT: In fact an issue was opened for this very recently: https://github.com/dandavison/delta/issues/130
Ideally, I think that a mouse click in an appropriate location in a terminal emulator window should open the user's editor on the correct line of the correct file.
1. Delta constructs the side-by-side diff itself (a parsed internal representation of it), and then colorizes it.
2. Delta gains the ability to parse side-by-side diffs being emitted by another tool.
My currently feeling is that (1) is more attractive / easier.
[0]: https://github.com/mookid/diffr
This does look nice, though I'm a little confused by the choice to highlight the section below the function declaration change even though it doesnt appear to have a change.
(I believe that one can customize the regular expressions that git uses to decide on the hunk header; they're sometimes appropriate and sometimes not, for the languages that I use.)
https://github.com/airblade/vim-gitgutter
A tip for people who (like me) don't like that Git pages by default: With Delta, you can disable this it by adding this to your environment: