tig
tig copied to clipboard
Support custom diff formatters (diff-so-fancy, delta etc)
It'd be nice if tig supported diff-so-fancy, as previously mentioned in #313.
just want to bump this!
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
Any updates on this issue? Did somebody get it working?
I'm curious about this too. I really like the clean view d-s-f gives.
I just learned about diff-so-fancy
myself. Bump and :+1:
diff-so-fancy support would be awesome! bump :)
This would be awesome !
Oh i need this Feature !
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:
- Tweaks the header of each touched file,
- Tweaks the hunk indicators to be more human readable,
- Strips the leading
+
and-
signs, - Marks empty lines, and
- 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:
- Teach
tig
to parse ANSI control characters, or - 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?
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?
@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 that's a good one, renamed the title 👍
would be waiting for diff-so-fancy support
+1 for formatters support
+1
+1 for delta support
+1 for delta support
+1 for delta support
+1 for delta support
+1 for delta support
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.
As you can see, the color picking is working as well. (left below pane is the original delta output without parsing ANSI.)
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
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.
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.
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.
I wrote how to setup in the PR above.
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.
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)
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.
Is there a way to force --paging=always
(in delta) from the git show
call?
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
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)'
@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?