dandavison / delta

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

No way to disable syntax in hunk header🐛 #1032

Closed washtubs closed 11 months ago

washtubs commented 2 years ago

The help menu seems to suggest that I can adjust this

    --hunk-header-style <STYLE>
        Style string for the hunk-header.

        See STYLES section. Special attributes 'file' and 'line-number' can be used to include the file path, and number of first hunk line, in the hunk header. The style 'omit' can be used to remove the hunk header section from the output.

        [default: "line-number syntax"]

However if I use --hunk-header-style "line-number" without specifying syntax I still see the syntax. I would think since I didn't specify syntax it wouldn't show that. I understand changing this might be considered "breaking". Is there any other way to keep the hunk header but not show the syntax? Maybe a new nosyntax option? Personally I like having the hunk headers clearly visible, but I find the syntax to just be distracting for the files I'm comparing.

deanhouseholder commented 2 years ago

+1 - I'm also annoyed by this as the syntax is often not helpful.

dandavison commented 2 years ago

Hey @washtubs, @deanhouseholder. I agree that it should let you do this! Are you sure it isn't working already though? A quick test:

git show | delta --no-gitconfig
image
git show | delta --no-gitconfig --hunk-header-style line-number
image

I'm also able to reproduce that using gitconfig

[delta]
   hunk-header-style = line-number
washtubs commented 2 years ago

Oh I don't mean the coloring, I was thinking in your second example, it should just be a box with "21:". That was my understanding of what syntax referred to unless I'm missing something?

dandavison commented 2 years ago

Ah, right! No, syntax says "I want syntax highlighting colors on this piece of text (assuming it can be interpreted as code in some programming language)"

We don't currently have a way to say "please hide the hunk header code fragment entirely".

However, you could set its foreground color to be equal to your background :)

E.g. --hunk-header-style 'line-number #000000' if you're on a black background.

I have a white background currently:

 git show | delta --no-gitconfig --hunk-header-style 'line-number #FFFFFF'
image

Of course, that leaves a large box... you could play with hunk-header-decoration-style:

--hunk-header-style 'line-number #FFFFFF' --hunk-header-decoration-style ul
image

Does anything along those lines achieve what you're looking for, at least as a workaround?

washtubs commented 2 years ago

It is a workaround for sure! I'm not too keen on the invisible text method as it's still gonna be there and still be selectable, not to mention I'm not confident I would be able to programmatically pick the right background color depending on the environment.

I did experiment with another setting, because I don't necessarily even need the line number, I tried --hunk-header-style=omit. This would have done it for me, however the problem with this one is because the boundary between hunks is just a blank line, there is no way to distinguish a boundary between two hunks vs a blank line within a hunk.

For example this is with a hunk header.

With hunk header

This is without a hunk header. Note that after - checkout there's no way for me to tell if that is the end of a hunk or just a continuation.

Without hunk header

deanhouseholder commented 2 years ago

In case it helps, this is exactly the problem I'm having and hoping for a solution to. @washtubs nailed it.

CodexHere commented 1 year ago

Adding another "+1" to the list here, I struggled fighting the settings to try and get things working but to no avail.

Another thing I noticed with hunk-header settings is only hunk-header-style is outputting when asking to show the config (filed here: https://github.com/dandavison/delta/issues/1458)

image

zmc commented 11 months ago

I ran into this today and decided to work on a patch to make it configurable. I have not filed a PR yet but you can view/try the branch at my fork (diff view).

My one hesitation is that while it technically won't change delta's default behavior, existing "themes" will drop the code fragment unless they are updated. This could be worked around by e.g. using no-code-fragment and inverting its logic, but I would like to hear what @dandavison thinks first if he's got a minute.

dandavison commented 11 months ago

Hi @zmc, I think your design is how it should have been initially. However, I'm not sure it's worth the breaking change today. We do already use the word "omit" with special meaning:

The style 'omit' can be used to remove the hunk header section from the output.

The attribute 'omit' is supported by commit-style, file-style, and hunk-header-style, meaning to remove the element entirely from the output.

So perhaps we should just call this omit-code-fragment? It's not beautiful, I agree.

Internally, I'd be happy for your implementation to use the non-inverted names that you are currently, i.e. HunkHeaderIncludeCodeFragment

zmc commented 11 months ago

Hi @zmc, I think your design is how it should have been initially. However, I'm not sure it's worth the breaking change today

Agreed - I don't like the idea of breaking anyone's existing configuration.

So perhaps we should just call this omit-code-fragment? It's not beautiful, I agree.

Internally, I'd be happy for your implementation to use the non-inverted names that you are currently, i.e. HunkHeaderIncludeCodeFragment

Ended up doing exactly this :)