Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove color for the common portions of lines that differ? --> Light vs Dark Mode challenges on macOS #464

Open
johnnyutahh opened this issue Mar 22, 2023 · 14 comments

Comments

@johnnyutahh
Copy link

Is there a way to remove color for the common portions of lines that differ... and only highlight the ports that differ (which d-s-f does so nicely with the red-backgrounded and green-backgrounded text)?

Disclaimers:

I highly suspect this is a FAQ or some existing config setting... but I could not find a reference anywhere. Maybe there's something there that I just don't understand. Apologies if I did not RTFM properly.

Also: I did not sea a Discussion section of this repo, else I would have made a new Discussion vs posting this Issue.

@scottchiefbaker
Copy link
Contributor

I suspect you want to change these config lines:

git config --global color.diff-highlight.oldNormal    "red bold"
git config --global color.diff-highlight.newNormal    "green bold"

You have to set them to whatever "normal" text color you use. If you set it to "" it will use the default DiffHightlight color and won't do what you want. As a test I set both of those to white and it did what I think you want.

@johnnyutahh
Copy link
Author

johnnyutahh commented Mar 23, 2023

I suspect you want to change these config lines:

git config --global color.diff-highlight.oldNormal    "red bold"
git config --global color.diff-highlight.newNormal    "green bold"

This is definitely going in the direction I seek, thanks @scottchiefbaker.

An initial problem (not sure if it's the only one, I've been testing for only 5 mins): "Light-vs-Dark Mode" (at least on my macOS v12.6.3 system). The foreground font color inverts in each mode, and setting "white" or "black" or some other "normal", "default", or "foreground" (and I've attempted all these aforementioned values in the quotes) foreground-text dolor .

The red/green font works well in both Light and Dark Modes (and I'm sure this is not a d-s-f coincidence).

@OJFord
Copy link
Member

OJFord commented Mar 23, 2023

Because if you use named colours then they'll follow the theme, if you used colour codes instead then of course you just get that colour, so would probably only be what you want in whichever mode you were in when you configured it.

@johnnyutahh
Copy link
Author

Hi @OJFord - are you suggesting that there's no way to auto-adjust for Dark-vs-Light Mode/themes? Or... are you suggesting some "codes" do exist that will auto-adjust?

Because if you use named colours then they'll follow the theme, if you used colour codes instead then of course you just get that colour, so would probably only be what you want in whichever mode you were in when you configured it.

@OJFord
Copy link
Member

OJFord commented Mar 23, 2023

No no, that what you have with named colours like red et al. is what you want. That leaves it to your terminal to decide what actual colour that is, which you might well want to be different according to whether the background colour is light or dark.

@johnnyutahh johnnyutahh changed the title Is there a way to remove color for the common portions of lines that differ? How to remove color for the common portions of lines that differ? Mar 23, 2023
@johnnyutahh
Copy link
Author

No no, that what you have with named colours like red et al. is what you want. That leaves it to your terminal to decide what actual colour that is, which you might well want to be different according to whether the background colour is light or dark.

Okay. My interpretation: named colors (like black, white and red) are expected to "do the right thing" when switching between Light and Dark modes on at least macOS v12.6.3.

Regardless, the following is doing what I want for this issue... at least it is now. Last night it was NOT working, for some reason. (Maybe it's because I restarted iTerm2.app since then? Hard to say/know.)

git config --global color.diff-highlight.oldNormal    "black"
git config --global color.diff-highlight.newNormal    "black"

Now, git diff --ignore-space-change (with d-s-f integration) is doing EXACTLY what I want. Many thanks to scottchiefbaker and OJFord for helping to make this happen(!).

[Closing this issue]

@johnnyutahh
Copy link
Author

johnnyutahh commented Mar 24, 2023

[Reopen-ing this issue]

Setting "black" foreground does not work for Dark Mode in macOS v12.6.3 (my system). In lieu of a better answer, I'll need to change my git config (swapping between "white" and "black" settings for below) each time I switch between Dark and Light Modes, respectively. I very-much welcome other suggestions.

git config --global color.diff-highlight.oldNormal    "black"
git config --global color.diff-highlight.newNormal    "black"

I was previously mistaken about an earlier fix solving this (without .gitconfig changes) ... and/or my "fix" above wasn't actually working... or something else has gone wonky.

@johnnyutahh johnnyutahh reopened this Mar 24, 2023
@OJFord
Copy link
Member

OJFord commented Mar 26, 2023

What do you mean by 'not working'? What actually happens/errors?

The highlighting is actually delegated to diff-highlight, and so bugs about that are unlikely to be dsf bugs.

Further, it's hard to say without knowing what isn't working exactly, but it's unlikely I think even to be a diff-highlight bug - if the colour is changing but just not what you want, then that's an issue with your configuration or terminal.

@scottchiefbaker
Copy link
Contributor

You could try "normal" for both oldNormal and newNormal. Color theming is really left up to the users config. I don't see an easy way to make a light and dark theme.

@scottchiefbaker
Copy link
Contributor

@johnnyutahh what is the status on this issue?

@johnnyutahh johnnyutahh changed the title How to remove color for the common portions of lines that differ? How to remove color for the common portions of lines that differ? --> Light vs Dark Mode challenges on macOS Jun 9, 2023
@johnnyutahh
Copy link
Author

johnnyutahh commented Jun 9, 2023

@scottchiefbaker - apologies I did not reply sooner. Does the following provide everything needed for this issue?

I was not able to get diff-so-fancy to auto-correct colors for Light-vs-Dark Mode on macOS . I tried several if not all of the color-value options mentioned above.

So I run a light-mode and dark-mode command/bash_function every time I change my macOS Light-vs-Dark Mode setting.

Details on the above commands/settings/config_files here:

https://gist.github.com/johnnyutahh/d6310eb416e846601ba4e86a9abd164e

@johnnyutahh
Copy link
Author

Additionally: if macOS light-vs-dark-mode handling is something that diff-so-fancy will specifically not support, than a pointer to this issue (or similar content) in the docs might (?) be helpful for future users. However, I can only speculate, I do not track full project context for this color/formatting-output stuff.

@OJFord
Copy link
Member

OJFord commented Jun 10, 2023

It's not really a case of diff-so-fancy not (or declining to) supporting it - it's just outside its concern.

The colours resulting from using dsf (as with plain git, or git with diff-highlight) are just codes for your terminal to render. It's the terminal which is (in some cases) the macOS application, and so the terminal which can interpret background/foreground/specificl colouring according to the OS's preferences.

Put another way, if you tell dsf 'print removed lines in red' in your config, then dsf tells your shell 'print this line in red' and your shell tells your terminal 'start printing in red' and your terminal looks up what colour 'red' is. If 'red' is different in light vs dark mode, that's the terminal's concern.

@johnnyutahh
Copy link
Author

johnnyutahh commented Jun 10, 2023

Thanks @OJFord, quite helpful. More comments:

Put another way, if you tell dsf 'print removed lines in red' in your config, then dsf tells your shell 'print this line in red' and your shell tells your terminal 'start printing in red' and your terminal looks up what colour 'red' is. If 'red' is different in light vs dark mode, that's the terminal's concern.

Right. Finding a way to configure "mapping/render" settings for iTerm2's light-dark-mode automatic changes, if it's a good/useful/"best" way to solve the problem I've highlighted at the end of this issue, would be quite useful for me. Suggestions welcome for said iTerm2-configuration, or any other "configurable" path.

...if I'm understanding things correctly.

However, I can appreciate this is or may be well outside of the scope of dsf.

Regardless: dsf provides me tremendous value -- thank you diff-so-fancy team!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants