[HN Gopher] Show HN: A syntax highlighter for Git and diff outpu... ___________________________________________________________________ Show HN: A syntax highlighter for Git and diff output, written in Rust Author : Myrmornis Score : 155 points Date : 2020-04-27 14:51 UTC (8 hours ago) (HTM) web link (github.com) (TXT) w3m dump (github.com) | lzybkr wrote: | If you to use this on Windows, you'll need to update `less.exe` | with my patched version - | https://github.com/lzybkr/less/releases/tag/fix_windows_vt | atombender wrote: | This is fantastic. Kudos! | | 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: export BAT_PAGER=cat | bdefore wrote: | 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. | nitsky wrote: | I ran into the same issue, and chose the same theme I use with | bat. | Myrmornis wrote: | Thank you! Fixed that. | bdefore wrote: | 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: | [pager] diff = delta --dark --plus- | color="#012800" --minus- color="#340001" --theme="zenburn" | eximius wrote: | icdiff is my current favorite. | | 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. | Myrmornis wrote: | 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.) | firloop wrote: | Anyone know how to get this working with vim-fugitive? | https://github.com/tpope/vim-fugitive | frou_dh wrote: | Does it work properly with `git add -p`? That's a longstanding | issue of diff-so-fancy: https://github.com/so-fancy/diff-so- | fancy/issues/35 | lzybkr wrote: | It does not, but it seems like a popular request: | https://github.com/dandavison/delta/issues/40 | OJFord wrote: | 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.) | Myrmornis wrote: | 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: [interactive] | diffFilter = delta --color-only | Klasiaster wrote: | A comparison to http://www.colordiff.org/ would be good in the | table of the README. | apas wrote: | 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 | | [0]: https://github.com/git/git/tree/master/contrib/diff- | highligh... | kyzn wrote: | I love that too! My config is almost the same, but I have | "pager = ..." under "[core]" | mookid11 wrote: | Sort of related: as I never made diff-highlight work correctly | on Windows, I wrote diffr[0] which goes a little bit behond | what diff-highlight does. | | [0]: https://github.com/mookid/diffr | kccqzy wrote: | 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. | Myrmornis wrote: | 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. | | 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. | [deleted] | Myrmornis wrote: | 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. | | [0] https://github.com/dandavison/delta | | [1] https://github.com/trishume/syntect | | [2] http://github.com/sharkdp/bat/ | yboris wrote: | Seems related: _diff2html_ | | https://diff2html.xyz/ | | npm-installed cli which shows you git diff in your browser | nitsky wrote: | Just installed it, it looks great and is a big step up from diff- | so-fancy. Thanks for making this! | j88439h84 wrote: | Can anybody suggest a --plus-color that looks nice on a | solarized-dark blue terminal? | j88439h84 wrote: | I can't tell if --dark is changing anything. That seems to be the | default on my dark terminal? | Myrmornis wrote: | Yes, --dark is the default and it will choose a dark theme. To | see a demo of other dark themes, you can do | delta --list-themes --dark | | and then delta --theme <chosen theme> to select it. | fallingmeat wrote: | can we get one written in Ada too? | loevborg wrote: | The light theme looks beautiful, thanks! | Myrmornis wrote: | 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. | ninjaranter wrote: | Is there a way to see diff output side-by-side? I personally find | that much easier to parse through with a widescreen monitor. | Myrmornis wrote: | Hi, thanks, this is an interesting question and there have been | requests for it. Two possibilities come to mind: | | 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. ___________________________________________________________________ (page generated 2020-04-27 23:00 UTC)