tig icon indicating copy to clipboard operation
tig copied to clipboard

Support custom diff formatters (diff-so-fancy, delta etc)

Open Liooo opened this issue 7 years ago • 34 comments

It'd be nice if tig supported diff-so-fancy, as previously mentioned in #313.

Liooo avatar Nov 20 '16 13:11 Liooo

just want to bump this!

diego898 avatar Feb 05 '18 22:02 diego898

Is there a workaround for this? diff-highlight is supported apparently, but I didn't quite get why diff-so-fancy isn't or what needs to be done to make it work

EnCey avatar Feb 21 '18 09:02 EnCey

Any updates on this issue? Did somebody get it working?

yilazius avatar Apr 24 '18 23:04 yilazius

I'm curious about this too. I really like the clean view d-s-f gives.

alok avatar May 22 '18 11:05 alok

I just learned about diff-so-fancy myself. Bump and :+1:

mathomp4 avatar Aug 31 '18 13:08 mathomp4

diff-so-fancy support would be awesome! bump :)

graves501 avatar Sep 08 '18 18:09 graves501

This would be awesome !

patrickelectric avatar Nov 01 '18 18:11 patrickelectric

Oh i need this Feature !

gwellner avatar Feb 28 '19 07:02 gwellner

I have looked into adding this support today. Unfortunately, I have not succeeded, and I currently think that I will take quite some effort to implement this support properly.

The diff-so-fancy tool works as a filter of the git diff output (as does diff-highlight which tig has support for). The filter does basically these things:

  1. Tweaks the header of each touched file,
  2. Tweaks the hunk indicators to be more human readable,
  3. Strips the leading + and - signs,
  4. Marks empty lines, and
  5. Adds a fair amount of coloring to different elements of the diff.

It is the added coloring that makes this a hard task. As @jonas mentions in #313,tig was only taught very basic parsing of ANSI control codes when support for diff-highlight was added. Actually, tig has a quite advanced support for coloring of the diffs built-in, and uses the --no-color flag when retrieving the diff, and proceeds to add colors afterwards.

The same could perhaps be done with diff-so-fancy, except that I have not found any way to suppress adding of the ANSI control characters to its output for many elements of the diff. (That could be a pull request to that tool, however, if desired.)

At my current level of understanding of the situation I see these ways forward for this feature:

  1. Teach tig to parse ANSI control characters, or
  2. Implement native support for the other items in the list of features that diff-so-fancy supports (items 1--4 in the list above basically).

I have tried to make tig parse the ANSI control characters, but was not completely successful. I have put this work in a branch, but it is in an extremely rough state, and not complete. (The parsing is probably mostly done, but applying the result in the form of e.g. colored output is not yet performed.) The code can be tested by setting the diff-highlight option to the path of the diff-so-fancy script in the tigrc config file.

Instead of pursuing down this road, I would suggest attempting the second instead: Implementing native support inside tig for the desired features offered by diff-so-fancy, except for its coloring. Feature request #855 targets one of these: Removal of diff + and - signs.

Or does someone else have a different opinion/suggestion?

andebjor avatar Mar 02 '19 20:03 andebjor

Note that PR #901 is opened. It should solve items 3 and 4 of the list @andebjor mentions above.

Items 1 and 2 should not be too difficult to implement in tig as well. These lines are already colored by tig.

And then the current/default implementation of diff-highlight (as described in the docs) can handle highlighting the differences within a line.

With that all done (note implementing item 1 and 2 is not even started and #901 is not merged yet) the mentioned features of diff-so-fancy are available in tig.
Or are we missing anything important?

ffes avatar Mar 11 '19 15:03 ffes

@Liooo can you rename the issue to something like Support custom diff formatters (diff-so-fancy, delta) ? I'd looooove to get diffs formatted & highlighted in tig by https://github.com/dandavison/delta .

ronjouch avatar Nov 22 '19 22:11 ronjouch

@ronjouch that's a good one, renamed the title 👍

Liooo avatar Dec 16 '19 08:12 Liooo

would be waiting for diff-so-fancy support

Viv1k avatar Jan 02 '20 08:01 Viv1k

+1 for formatters support

DeH4er avatar Jan 14 '20 07:01 DeH4er

+1

pkaush avatar May 14 '20 19:05 pkaush

+1 for delta support

liquidz avatar May 27 '20 00:05 liquidz

+1 for delta support

sharefantasy avatar Jul 07 '20 02:07 sharefantasy

+1 for delta support

flw-cn avatar Aug 22 '20 06:08 flw-cn

+1 for delta support

booc0mtaco avatar Sep 14 '20 22:09 booc0mtaco

+1 for delta support

ress997 avatar Dec 29 '20 18:12 ress997

Hi, I'm a contributor to delta, and I'm starting to implement delta support together with ANSI support in tig. As you can see in the image below, it is already close to completion. Don't care about commit message, I'll clean up after completion.

ss 0003-08-14 at 3 54 11

As you can see, the color picking is working as well. (left below pane is the original delta output without parsing ANSI.)

ss 0003-08-14 at 3 58 35

The problem is that ncurses needs to initialize color combinations in initialization, and I'm not sure how to implement the infinite number of RGB color combinations for delta.

It may be going to take a lot of time this part, so if anyone has any ideas, please let me know. (I tried init_pair everytime but it won't work as expected of course. maybe we need to restrict users to use only one theme).

discussion is here, I may going to limit options with delta by setting "true-color never". https://github.com/dandavison/delta/discussions/689

ghost avatar Aug 13 '21 19:08 ghost

update: I've been trying and found the way to handle delta colors. It's still not perfect as you see but I know where to fix. Hopefully I can send PR in this week.

ss 0003-08-16 at 2 23 16

P.S.

I have a question to people who want to use delta inside tig.

Do you want turn off side-by-side inside tig by default? I felt it's kinda annoying and it seems to be broken easily when tig split right-left, since you can't force tig to split top-under at default.

ghost avatar Aug 15 '21 18:08 ghost

update:

https://github.com/jonas/tig/pull/1140

I think it is finished and I would like someone to test it because I've only tested it with iTerm on MacOS.

ss 0003-08-17 at 19 11 58 ss 0003-08-17 at 19 12 36

I wrote how to setup in the PR above.

ghost avatar Aug 17 '21 10:08 ghost

Do you want turn off side-by-side inside tig by default? I felt it's kinda annoying and it seems to be broken easily when tig split right-left, since you can't force tig to split top-under at default.

You can put this setting in the tig configuration: set vertical-split = false to force tig to split top-under at default.

Regarding side-by-side, it would go to allow tigrc to accept options and allow users to set width freely. Another idea it is to see why delta appears so small, and check if tig can send the right width terminal automatically to delta, so it can be readjusted rather than choosing a fix size.

pablospe avatar Aug 22 '21 14:08 pablospe

Anyone manage to build this on macOS yet?

edit: nvm, managed to

ijoseph avatar Sep 01 '22 17:09 ijoseph

Might a workaround for now be to use the bind command from tig?

By adding the following lines to your .gitconfig it is possible to view the current commit with your favorite git pager by clicking d in tig.

[tig "bind"]
    generic = d >git show %(commit)

oberprah avatar Sep 06 '22 16:09 oberprah

Amazing workaround, thanks a lot!

I think I prefer using it with enter (probably there is a drawback for this, need to test it more):

[tig "bind"]
    generic = "<enter>" >git show %(commit)

Is there a way to open a windows and show this? Similar to the fzf-preview. Maybe a workaround with tmux.

pablospe avatar Sep 07 '22 14:09 pablospe

Is there a way to force --paging=always (in delta) from the git show call?

pablospe avatar Sep 07 '22 15:09 pablospe

Is there a way to force --paging=always (in delta) from the git show call?

This can be achieved by adding the following lines to .gitconfig

[delta]
    paging = always

oberprah avatar Sep 07 '22 21:09 oberprah

after get delta set up with git, I use tig + tmux to view diff, put the following mapping to .tigrc, move cursor to a commit hash in tig, then press '@' shortcut to open delta in a split tmux pane. this mapping handles the paging issue for a short diff output:

bind generic @ @tmux split-window -l 80% 'LESS= DELTA_PAGER="less -R" git show %(commit)'

linsong avatar Sep 08 '22 01:09 linsong

@oberprah Thanks! I prefer to set paging = auto, so the short outputs are just displaying and exit (so no need of paging and I avoid pressing 'q' to exit :P).

@linsong Great solution! I like the config it is inside tig instead of gitconfig. Maybe it is good idea to clarify in your comment that tig should run inside tmux in order to work. Btw, is there a way reuse the same tmux split? Let's say you return to the split where tig is running and press again @, currently it will open another split which it is not ideal.

Why is the LESS= needed? I also added few options to the DELTA_PAGER="less -RKc". My command so far:

Also, what if tig is not running inside tmux? Would a similar thing be possible with a mapping?

pablospe avatar Sep 08 '22 14:09 pablospe