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

Background color issues #87

Closed
elbaro opened this issue Jan 17, 2020 · 11 comments · Fixed by #114
Closed

Background color issues #87

elbaro opened this issue Jan 17, 2020 · 11 comments · Fixed by #114

Comments

@elbaro
Copy link

elbaro commented Jan 17, 2020

image

Alacritty 0.4.0, delta 0.0.15

All light themes are broken.
Somehow --minus-color=xx does not set to xx, but adds xx.
--minus-color="#000000" shows minus diffs with no color.

@dandavison
Copy link
Owner

Hi @elbaro, there was another user having issues with alacritty recently. Is this relevant to your problem? #79 (comment)

@dandavison
Copy link
Owner

Also, can you confirm that the 24bit color tests linked in the README are passing for you? https://github.com/dandavison/delta#24-bit-color

@elbaro
Copy link
Author

elbaro commented Jan 17, 2020

I tried out-of-box iTerm2 on Mac and Kitty on Linux, and the same problem happenes. The 24-bit color test works fine.

@dandavison
Copy link
Owner

OK, can you explain a bit more what the problem is exactly? In the screen shot above, it looks like you are using a light theme, but have a dark terminal background. Normally one would only use a light theme with a light terminal background. Sorry if I'm being slow! What exactly is the problem that the screenshot illustrates?

@elbaro
Copy link
Author

elbaro commented Jan 17, 2020

Are you saying that to reproduce the screenshot in README.md, one has to use the terminal with #FFFFFF background? In the screenshot, the fonts in the red line is invisible. Can we have --ignore-term-color for 24bit env to show the exact colors intended?

Also this may be a separate issue, but I am seeing a different behavior depending on the color:

git diff | delta --light --minus-color="#000000"
image

git diff | delta --light --minus-color="#111111"
image

@dandavison
Copy link
Owner

dandavison commented Jan 17, 2020

Are you saying that to reproduce the screenshot in README.md, one has to use the terminal with #FFFFFF background?

Yes, that's right, delta only applies the red and green background colors to convey diff information: it doesn't apply a "default" background color to all the text it emits. (Actually the screenshot is with iTerm2 "Material" theme which is some sort of pearl / off-white background).

Can we have --ignore-term-color for 24bit env to show the exact colors intended?

That could be possible. Am I right in thinking that this feature does not exist in bat and that it would be equally appropriate there?

I am seeing a different behavior depending on the color:

Can you post some raw output from git diff that is resulting in this behavior? (I.e. as text, not as a screenshot).

@elbaro
Copy link
Author

elbaro commented Jan 18, 2020

bat is already using the fixed color.
I opened two terminals, one with white theme and one with dark theme.

In both terminals, #include has a color #f92672.

Here is delta:

The red line's foreground color is different (include #dddddd vs #4d4d4c)
The green line's foreground color is same (if #a71d5d)
The other lines' foreground color is same (#333333)


For the second issue, this can reproduce:
❯ cat diff      
diff --git a/test.cc b/test.cc
index a6e4e99..7cb67e1 100644
--- a/test.cc
+++ b/test.cc
@@ -1,8 +1,9 @@
-#include <stdio.h>
+#include <cstdio>
 
-void main() {
-	if(1) {
+int main() {
+	if(true) {
 		;
 	}
+	retunr 0;
 }

git diff |  delta --light --minus-color="#000000" 
git diff |  delta --light

@dandavison
Copy link
Owner

Thank you! I can reproduce this; will look into it.

@dandavison
Copy link
Owner

@elbaro the color overrun bug you reported (git diff | delta --light --minus-color="#000000") is fixed in master. Thanks very much for reporting that. I know there are one or two remaining issues in this ticket though!

@dandavison
Copy link
Owner

Perhaps relevant to the other issues mentioned in here, I've merged a few branches in the last week that I believe improve the ways colors are handled internally, and improve the CLI for specifying colors. So to summarize what delta does and does not do (without any implication as to whether these are bugs or features!):

  • Delta allows the syntax highlighting theme specified by --theme or the BAT_THEME env var to alter foreground colors of code. However, delta does not do this in the removed (red background) sections (to limit the color salad). In red sections you will be getting whatever foreground color is configured in your terminal emulator (This is the cause of one of the issues reported in this ticket).

  • Delta applies 4 background colors to certain regions of code in diffs. Some regions of code do not receive a background color.

All color command line options can be specified either as explicit 24-bit RGBs, or as one of the 256 ANSI codes (see --help). With the recent changes, delta will automatically choose an 8-bit approximation to any 24-bit colors when it detects an 8-bit color terminal environment.

The following text is now printed out at the end of the --help text:

Colors
------

All delta color options work the same way. There are two ways to specify a color:

1. RGB hex code

   An example of passing an RGB hex code is:
   --file-color="#0e7c0e"

2. ANSI color name

   There are 8 ANSI color names:
   black, red, green, yellow, blue, magenta, cyan, white.

   In addition, all of them have a bright form:
   bright-black, bright-red, bright-green, bright-yellow, bright-blue, bright-magenta, bright-cyan, bright-white

   An example is:
   --file-color="green"

   Unlike RGB hex codes, ANSI color names are just names: you can choose the exact color that each
   name corresponds to in the settings of your terminal application (the application you use to run
   command line programs). This means that if you use ANSI color names, and you change the color
   theme used by your terminal, then delta's colors will respond automatically, without needing to
   change the delta command line.

   "purple" is accepted as a synonym for "magenta". Color names and codes are case-insensitive.

@dandavison
Copy link
Owner

@elbaro I believe all the issues you described here are finally fixed in master. Please see the write-up in #205.

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

Successfully merging a pull request may close this issue.

2 participants