dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
24.16k stars 391 forks source link

🚀 Colorization of commit header? #816

Open unphased opened 2 years ago

unphased commented 2 years ago

I noticed that when I set the

[delta "decorations"]
  commit-style = yellow bold
  commit-decoration-style = bold yellow box ul

settings, the entire commit line becomes yellow. Including any indicators for HEAD, local or remote branch names.

I would like these to be made visually distinct for easier reading. I noticed that it's possible to use --pretty=format here.

I have tried using this format which I directly copied out of my short git graph log configuration: --pretty=format:'%C(bold magenta)%h%Creset -%C(auto)%d%Creset %s %Cgreen%ci %C(yellow)(%cr) %C(bold blue)<%an>%Creset'

And it looks like:

image

This works, but completely overrides delta's configured commit styles.

I feel like in the past I had this working prior to discovering Delta, but now I wonder if I may be mistaken about that and i always just had them yellow.

Anyways, since it overrides, there is no way to configure the colors precisely this way and gain the benefits of Delta's styling such as boxes. Let's say I wanted box decoration. I don't, to save space, but somebody might.

In the meantime (and in the future I reckon) I will use it like I have it now with --pretty=format but tweaked a bit (needs more yellow) to suit my needs. This ticket is regarding whether to do anything about the intersection between git's styling and Delta's styling.

dandavison commented 2 years ago

Is the following an accurate summary?

This ticket calls for the two things to be possible in conjunction.

unphased commented 2 years ago

Thank you for summarizing!

I am not certain that the first bullet is entirely the case. Is raw the default? I seem to recall from my testing that when I made git emit colors that these git colors overrode, even when the delta commit-style was set.

dandavison commented 2 years ago

Yep, raw is the default

~ delta --no-gitconfig --show-config | grep commit-style
    commit-style                  = raw

and I believe it works; try git show --color=always --decorate | delta --no-gitconfig

image

(I found that git show doesn't emit the decorated refs if it's output is redirected to a pipe unless we pass --decorate)

sebszyller commented 2 years ago

I've run into a similar issue. It looks like there's some discrepancy between how the colours are handled for git show and git log. I've been debugging it for a while, and it seems that there's an issue with how delta is used from git, and not with the git+delta combination on its own.

Format string: --pretty=format:" %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset"

Case 1 (pipe git show to delta) - works as desired:

git show --color=always --decorate --pretty=format:" %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" | delta --no-gitconfig

works

Case 2 (don't pipe git show manually; rely on automatic formatting) - no colour but format is fine:

git show --color=always --decorate --pretty=format:" %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset"

doesnt

Case 3 (don't pipe git log -pmanually; rely on automatic formatting) - works as desired:

git log -p --pretty=format:"%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset"

works-p

TLDR; I would like git show to use the formatting string correctly, just like git log does.

I'm using a very basic configuration in .gitconfig:

[core]
    pager = delta

[interactive]
    diffFilter = delta --color-only

[delta]
    navigate = true  # use n and N to move between diff sections
    side-by-side = true

[merge]
    conflictstyle = diff3

[diff]
    colorMoved = default