support delta along with ANSI support
https://github.com/jonas/tig/issues/542#issuecomment-899094741
- All test passes.
- I haven't seen segmentation faults with newest versions of MacOS Big Sur, iTerm2, and delta. ncurses version is 6.2.
- It looks like no performance issues.
- I've only tested it with Terminal.app and iTerm on MacOS.

how to use delta in tig
It requires ncurse 6.1 or higher.
# if you don't have ncurses
curl -O ftp://ftp.gnu.org/gnu/ncurses/ncurses-6.2.tar.gz
tar -xzvf ncurses-6.2.tar.gz
cd ncurses-6.2
./configure --prefix=${where you like} --enable-pc-files --with-pkg-config-libdir=/usr/local/bin/pkgconfig --enable-sigwinch --enable-symlinks --enable-widec --with-shared --with-gpm=no --without-ada --enable-ext-colors # i set the path as /usr/local which is default
sudo make
sudo make install
cd ${path to tig of the branch of above PR}
make configure
./configure LDFLAGS=-L${where you download ncurses}/lib CPPFLAGS=-I{where you installed ncurses}/include # i set the path as /usr/local/opt/ncurses which is installed by ncurses
make
echo "set diff-highlight = \"delta\"" >> ~/.tigrc
./src/tig
Great stuff.
How is the current line highlighting expected to work? I found it a bit surprising:

I also seem to get some line skew with very long lines:

Hi hasufell, thank you for catching. I'll fix those.
ps I noticed that scrolling right breaks the beginning of the line as well.
@ulwlu hi, here to respond to your call for tests at https://github.com/jonas/tig/issues/542#issuecomment-900179550 .
Your branch compiles and works for me (Arch Linux / Kitty 0.23.1, ncurses 6.2, delta 0.8.3) 🙂.
In addition to the weird line highlight already reported, I was surprised to see delta-within-tig uses a gray background. I'm not sure why, as pure delta outside of tig uses a black background. My delta config is empty, and my ~/.tigrc is empty except for the single line set diff-highlight = "delta". Is it a side-effect of the true color issue you mentioned? Feel free to ask for new tests with different color config.
Screencast below (pure delta at the beginning from 0:00 to 0:07, delta-in-tig afterwards):
https://user-images.githubusercontent.com/522085/129816178-73f18a78-b889-4aae-ab09-73d91c7a605a.mp4
@ronjouch Hi, thank you for catching and details. I'm still not sure if this is caused by coloring problem, but I'm thinking delta gave some background color info with '--trur-color =never' that is not close to real true-color.
I'll check it anyway. Thank you very much
Thank you very much
Much obliged; thank you for the work on this!
I'm still not sure if this is caused by coloring problem, but I'm thinking delta gave some background color info with '--trur-color =never' that is not close to real true-color.
@ulwlu I did a bit more monkeying around with my Kitty color config. The problem doesn't appear by default. But with my Kitty color config (pasted below), it does.
#: The color table {{{
#: The 256 terminal colors. There are 8 basic colors, each color has a
#: dull and bright version, for the first 16 colors. You can set the
#: remaining 240 colors as color16 to color255.
color0 #555753
color8 #777777
#: black
color1 #ef2929
color9 #cc0000
#: red
color2 #8ae234
color10 #4e9a06
#: green
color3 #fce94f
color11 #c4a000
#: yellow
color4 #729fcf
color12 #3465a4
#: blue
color5 #ad7fa8
color13 #75507b
#: magenta
color6 #34e2e2
color14 #06989a
#: cyan
color7 #eeeeec
color15 #d3d7cf
#: white
Another details. Have you tried side-by-side mode? It seems to work but only until 80 chars. So, I was thinking to use delta --width 250, but this doesn't seem to work: set diff-highlight = "delta --width 250". How do you pass parameters?
I've also observed a weird highlighting, gray background. I am using konsole.
Also noticed that when there are many files and you press enter to the filename (in the commit header), it doesn't jump to beginning of the file in the diff. Instead I received this error:
[diff] Press '<Enter>' to jump to file diff - line 11 of 88
Failed to find file diff
@hasufell @ronjouch
Hi. I've successfully fixed those, but I've come up with a better design. So I've decided to refactor it, which should take about a week.
@pablospe
Tig can't accept formatter options. I can fix that but it will be on another PR since it has some impact on another function. Currently could you set config locally?
Tig can't accept formatter options. I can fix that but it will be on another PR since it has some impact on another function. Currently could you set config locally?
Apologies, I didn't understand. What do you mean by set config locally? Having an alias or something like that to avoid options?
@pablospe
Sorry for the lack of explanation, please do the following at this time.
git config delta.width 250
From your explanation, I think you don't want to set it to global. However, tig does not accept options now, so please set locally like this inside repositories that you use tig. Currently tig searches only executable binary, so alias doesn't work either. I will probably fix it to accept options if jonas agreed.
Also, in the original issue I asked what to do with the side-by-side option inside tig. If you have time, please feel free to post something like "allow tigrc to accept options and allow users to set width freely", so that someone may post an another idea.
https://github.com/jonas/tig/issues/542#issuecomment-899094741
Also another problem I found is that in navigation mode for delta doesn't work:
n and N keybindings to move between files in large diffs, and between diffs in log -p views (--navigate). See in delta documentation (here)
I am just reporting the problems I found. Thanks a lot for the fantastic work, @ulwlu!
I haven't checked the implementation details but this looks a bit weird on light terminals like gnome-terminal or xterm because it draws dark backgrounds.
@krobelus Hi. Yes that occured because of here.
https://github.com/jonas/tig/pull/1140/files#diff-3cd1efc51226a700b579928f3ee8477ed1a05715a60b2d6e0b1fc54e63969581R50
I noticed that and fixed it into default_bg. Thank you for catching.
Currently I'm fixing a bit of functions which pablospe mentioned and more else.
Maybe some of the changes can be separated in other PRs and add basic delta support on master? Even if it is not perfect, it would be good to have the delta support.
@pablospe sorry to be late. I was busy with my work and time flies so fast. That sounds great, I wanna add at least one more feature then.
- [x] handle delta output and draw correct color
- [x] draw correct current cursor
- [x] calculate the correct line length ( so that the line won't be overwrapped)
- [x] handle correct pager <- i want to add at least this one (edit: done on 2/7)
These can be called basic feature, and we can add some features such as jumping to the file hunks.
I probably can add in this year, or at least next January
p.s. on 2022/1/21
I finally have some time to focus on this, so I start working on it.
I'm sorry for the delay, but I had a service launch on 1/16 at work and had been so busy until that, and in my personal life.
p.s. on 2022/2/4
i'm close to complete pager func. please give me a while.

@hasufell
- fixed selected cursor
- fixed long line wrapping
@ronjouch
I don’t have kitty env but I think I have fixed your case.
- Respecting the terminal's specified background color instead of COLOR0
@krobelus
- Applied light theme

@pablospe
Sorry for having kept you waiting, as I wrote I was quite busy up to now. I would love you to check if you have a time again.
I also added a test and fixed a pager bug.
@ronjouch I don’t have kitty env but I think I have fixed your case.
- Respecting the terminal's specified background color instead of COLOR0
@ulwlu thanks, fix confirmed! I'll be running 629a12e and will report new problems here.
EDIT 2022-02-15 been running this branch for a week, so far it's smooth sailing for me.
Looks good to me! Thanks for the great job, @ulwlu! @jonas Who can approve this PR to be merged?
thank you pablospe for your review!
probably @koutcher would you review this PR?
I've compiled 5ae769b and am having a segmentation fault on Linux. I compiled with "make all-debug" and then ran tig via gdb and the crash is happening in draw_ansi() on line 151: the color_method_mark variable is null.
The crash seems related to lines like the following in my ~/.gitconfig:
minus-emph-style = bold red 52
If a line like that is present (i.e. a line with a background color), then the crash happens pretty reliably. Deleting the background color (i.e. the 52) from that line makes the crash go away. Note that even if the crash goes away, I still see some erratic behavior where delta sometimes doesn't display the diff correctly.
@mbsulliv thank you for catching, i confirmed the bug. It happens with the following string example,
^[[34m^[[38;5;88m 28 ^[[34m⋮^[[38;5;28m ^[[34m│^[[31mvoid draw_ansi(struct view *view, int *ansi_num, char **ansi_ptrs);^[[1;4;32m*^[[0m
.... because strchr of ';' gets wrong if-condition before the exact line where you pointed out color_method_mark.
I didn't know the format \033[1;4;32.
this should be covered, i appreciate your catching. I'll fix and add a test as well. (until next Wednesday)
As an experiment, I made the following one line change to avoid the segfault (displayed here using git diff):

I'm not actually suggesting that as a fix -- I'm just using it as a diff to illustrate a problem I'm seeing in tig's display of the same change. My delta settings above are basically:
--diff-so-fancy--syntax-theme none
There are a few more delta color tweaks, but I don't think they're important. When using similar settings with tig's delta, the change is displayed like this:

I'm guessing that your actual fix will address this, but I wanted to make sure you were aware that it wasn't drawing correctly with these particular delta settings.
@mbsulliv Hey, can you try again with the latest commit 4d783f7 when you have time?
As I mentioned a few days ago, this is caused by unexpected ansi-code being inserted (such as \033[1;4;32). I couldn't notice without your pointing, so I appreciate you.

Hi, In diff view, the file jump feature does not work properly and show error message: "Failed to find file diff"
@fengyichui please see the comment above, this supports only the basic feature.
Maybe some of the changes can be separated in other PRs and add basic delta support on master? Even if it is not perfect, it would be good to have the delta support.
@ulwlu Sorry, I don't quite understand, do you mean it's already supported or need other PRs ?
it needs an other PR.
@ulwlu Thanks for your answer.
Looking forward to seeing this merged, awesome, thanks!