jonas / tig

Text-mode interface for git
https://jonas.github.io/tig/
GNU General Public License v2.0
12.37k stars 605 forks source link

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

Open Liooo opened 7 years ago

Liooo commented 7 years ago

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

diego898 commented 6 years ago

just want to bump this!

EnCey commented 6 years ago

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

yilazius commented 6 years ago

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

alok commented 6 years ago

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

mathomp4 commented 6 years ago

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

graves501 commented 6 years ago

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

patrickelectric commented 5 years ago

This would be awesome !

gwellner commented 5 years ago

Oh i need this Feature !

andebjor commented 5 years ago

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?

ffes commented 5 years ago

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?

ronjouch commented 4 years ago

@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 .

Liooo commented 4 years ago

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

Viv1k commented 4 years ago

would be waiting for diff-so-fancy support

DeH4er commented 4 years ago

+1 for formatters support

pkaush commented 4 years ago

+1

liquidz commented 4 years ago

+1 for delta support

sharefantasy commented 4 years ago

+1 for delta support

flw-cn commented 4 years ago

+1 for delta support

booc0mtaco commented 4 years ago

+1 for delta support

ghost commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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.

pablospe commented 3 years ago

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.

ijoseph commented 2 years ago

Anyone manage to build this on macOS yet?

edit: nvm, managed to

oberprah commented 2 years ago

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)
pablospe commented 2 years ago

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 commented 2 years ago

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

oberprah commented 2 years ago

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
linsong commented 2 years ago

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)'
pablospe commented 2 years ago

@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 commented 2 years ago

Here also some examples using tmux popup. Put the following mapping to .tigrc:

(floating in the middle of the screen)

bind generic d @tmux popup -w 95% -h 90% -E 'DELTA_PAGER="less -RKc" git show %(commit)'

(spliting in the bottom half)

bind generic d @tmux popup -y 100% -w 100% -h 50% -E 'DELTA_PAGER="less -RKc" git show %(commit)'

Note: tig should be running inside tmux >3.3. Thanks @oberprah and @linsong.

linsong commented 2 years ago

@pablospe welcome

After googling and reading tmux man page for a while, I improve my previous binding a bit, it will reuse the same split tmux pane now:

bind generic @ @sh -c "\
  ( \
    tmux has-session -t '.{last}' \
    && tmux respawn-pane -t '.{last}' -k 'LESS= DELTA_PAGER=\"less -R\" git show %(commit)' \
  ) \
  || tmux split-window -l 80% 'LESS= DELTA_PAGER=\"less -R\" git show %(commit)'"

Off course you can continue to improve this binding to check if running under tmux or not in the shell command, but I use tmux all the time, so I skip that part.

pablospe commented 2 years ago

This is the best solution so far, thanks!

AndrewKvalheim commented 5 months ago

Similar to the tmux workaround, I’ve been using a kitty overlay via:

bind generic d @kitten @ launch --self --type=overlay --title=current --cwd=current --env DELTA_PAGER='less -+F' git show %(commit)