dandavison / magit-delta

Use delta (https://github.com/dandavison/delta) when viewing diffs in Magit
MIT License
285 stars 10 forks source link

additions/removals not highlighted with magit-delta #12

Closed hboetes closed 3 years ago

hboetes commented 3 years ago

I just changed the indenting of this line, displayed with git diff

image

As you can see the spaces I added are hilighted. When I display the same change in magit, those added spaces are not highlighted.

How can I configure magit-delta to use the same hilighting as in the console?

hboetes commented 3 years ago

Here is a side by side example, the first is from magit in Emacs, which has full 256 colour support BTW. image And the second is from terminator, whilst running git diff. image

dandavison commented 3 years ago

Hi @hboetes, let's get to the bottom of this. Do you see any within-line highlighting at all when using magit-delta? In general you should (like the word "Copy" in the screenshot in the README).

What is the value of the variable xterm-color--support-truecolor in your Emacs?

Here's something to try:

  1. Capture some delta output with its ANSI escape sequences:

    git diff | delta > with-ansi-colors.txt
  2. Open with-ansi-colors.txt in Emacs. You should see lots of raw ANSI escape sequences in the emacs buffer, like ^[[38;5;4m

  3. Do M-x xterm-color-colorize-buffer. That should suddenly make colors appear: i.e. it converts all the raw ANSI color escape codes into Emacs text properties. Does it look right? It should look the same as in your terminal.

hboetes commented 3 years ago

Hello Dan,

Thanks for your time:

xterm-color--support-truecolor is a variable defined in ‘xterm-color.el’. Its value is t

Here is the result from git diff, which looks perfectly splendid:

[image: image.png]

This is the result of the file with-ansi-colors.txt in emacs with xterm-color-colorize-buffer, which does something wrong.

[image: image.png]

Here is my init.el for reference: https://raw.githubusercontent.com/hboetes/configs/master/.config/emacs/init.el Which I also tried whilst commenting out:

(custom-theme-set-faces 'zenburn '(font-lock-comment-face ((t (:foreground "#DFAF8F")))) '(font-lock-comment-delimiter-face ((t (:foreground "#DFAF8F")))))

And I also commented out using the zenburn theme completely, with the same result.

% emacs --version GNU Emacs 28.0.50

./configure --with-x --with-x-toolkit=gtk --without-makeinfo --mandir=/usr/local/man

dandavison commented 3 years ago

This is the result of the file with-ansi-colors.txt in emacs with xterm-color-colorize-buffer, which does something wrong.

Hi @hboetes, the formatting in your reply got messed up unfortunately, so I can't see your screenshot.

Could you try M-x xterm-color-test please? Here's what I get:

image

hboetes commented 3 years ago

Hello Dan, whilst running emacs as an X application it looks right, but whilst running in terminator I get this: image

I tried the same in alacritty: image

image

Sooo.... Which terminal are you using? And do you have a config file for that terminal which you might want to share?

Mine are over here: https://raw.githubusercontent.com/hboetes/configs/master/.config/alacritty/alacritty.yml https://raw.githubusercontent.com/hboetes/configs/master/.config/terminator/config

dandavison commented 3 years ago

Hey @hboetes, the replies being sent by your mail client aren't getting formatted correctly in github! Would you be able to post them directly in the github web UI (or smartphone app)?

hboetes commented 3 years ago

Sorry about that, I've updated the comments, the image links work but are not rendered, no idea what causes that.

dandavison commented 3 years ago

OK, so that sounds like the problem is something to do with display of colors when emacs is running in a terminal emulator. Can you try running these color test scripts in your terminal emulator?

https://gitlab.com/gnachman/iterm2/-/raw/adhoc_3.3.20190827_203700/tests/24-bit-color.sh

image

https://github.com/atomontage/xterm-color/tree/master/tests

image

What is the value of the COLORTERM and TERM environment variables in your shell (echo $TERM) and as seen by emacs (getenv "TERM")?

dandavison commented 3 years ago

(I don't use Emacs a terminal application.)

hboetes commented 3 years ago

image image

% echo $TERM
xterm-256color
% echo $COLORTERM
truecolor

getenv TERM returns dumb getenv COLORTERM returns [no match]

dandavison commented 3 years ago

Great, so it looks like there's no problem with your terminal.

OK, I'm seeing the same as you when I run emacs as a terminal application (emacs -nw): the xterm-color-test output does not look correct:

image

I'm not sure why this is, and I'm not 100% sure what our expectations should be. @atomontage (author of xterm-color) do you have time to advise here? In a terminal emulator that is displaying 256 and truecolor colors correctly, should the xterm-color-test results render correctly in an emacs -nw?

hboetes commented 3 years ago

Might this be of interest? https://www.gnu.org/software/emacs/manual/html_node/efaq/Colors-on-a-TTY.html

hboetes commented 3 years ago

Well I'll be damned o_O, that did the trick! image

image

dandavison commented 3 years ago

Yeah! I just found the same.

image

OK, great. So I'll add a note to the README pointing to that emacs doc page for people who want to use magit-delta with emacs running in a terminal.

Thanks for exploring this avenue!

hboetes commented 3 years ago

Just to show off everything works now, emacs on OpenBSD in tmux with full color support for delta. Yay! image