Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Liooo opened this issue Nov 20, 2016 · 34 comments
Open

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

Liooo opened this issue Nov 20, 2016 · 34 comments

Comments

@Liooo
Copy link

Liooo commented Nov 20, 2016

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

@diego898
Copy link

diego898 commented Feb 5, 2018

just want to bump this!

@EnCey
Copy link

EnCey commented Feb 21, 2018

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
Copy link

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

@alok
Copy link

alok commented May 22, 2018

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

@mathomp4
Copy link

I just learned about diff-so-fancy myself. Bump and 👍

@graves501
Copy link

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

@patrickelectric
Copy link

This would be awesome !

@gwellner
Copy link

Oh i need this Feature !

@andebjor
Copy link
Contributor

andebjor commented Mar 2, 2019

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
Copy link
Contributor

ffes commented Mar 11, 2019

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
Copy link
Contributor

@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 Liooo changed the title Supporting diff-so-fancy in diff view Support custom diff formatters (diff-so-fancy, delta etc) Dec 16, 2019
@Liooo
Copy link
Author

Liooo commented Dec 16, 2019

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

@Viv1k
Copy link

Viv1k commented Jan 2, 2020

would be waiting for diff-so-fancy support

@DeH4er
Copy link

DeH4er commented Jan 14, 2020

+1 for formatters support

@pkaush
Copy link

pkaush commented May 14, 2020

+1

@liquidz
Copy link

liquidz commented May 27, 2020

+1 for delta support

@sharefantasy
Copy link

+1 for delta support

2 similar comments
@flw-cn
Copy link

flw-cn commented Aug 22, 2020

+1 for delta support

@booc0mtaco
Copy link

+1 for delta support

@ghost
Copy link

ghost commented Aug 13, 2021

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".
dandavison/delta#689

@ghost
Copy link

ghost commented Aug 15, 2021

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
Copy link

ghost commented Aug 17, 2021

update:

#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
Copy link

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.

thomasjachmann added a commit to thomasjachmann/dotfiles that referenced this issue May 9, 2022
Until tig can use more fancy differs (eg when git is configured to use
delta), this will use `git diff` under the hood to achieve this a bit
more cumbersomely.

see jonas/tig#542
@ijoseph
Copy link

ijoseph commented Sep 1, 2022

Anyone manage to build this on macOS yet?

edit: nvm, managed to

@oberprah
Copy link

oberprah commented Sep 6, 2022

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
Copy link

pablospe commented Sep 7, 2022

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
Copy link

pablospe commented Sep 7, 2022

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

@oberprah
Copy link

oberprah commented Sep 7, 2022

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
Copy link

linsong commented Sep 8, 2022

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
Copy link

pablospe commented Sep 8, 2022

@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
Copy link

pablospe commented Sep 8, 2022

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
Copy link

linsong commented Sep 9, 2022

@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
Copy link

pablospe commented Sep 9, 2022

This is the best solution so far, thanks!

@AndrewKvalheim
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests