romkatv / powerlevel10k

A Zsh theme

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Changing Background Affects Foreground

Piero24 opened this issue · comments

I'm trying to change the background of my theme, but unfortunately, when I change the background color, it also changes the foreground.
I have tried in many different parts of the .p10k-zsh file, but unfortunately, the result is the same.

Here is an example:

Now I have the following colors for the background and the foreground:

1_a 1_b

When I change the value for POWERLEVEL9K_DIR_BACKGROUND from 4 to 38, it automatically changes the color of the font as well, and the new result is like this one.

2_a 2_b

But if the final result I want to have is the foreground color of the first one and the background color of the second one.

This happens with many other foregrounds, as if they had a black halo behind them. Another example is when I try to change the color for the `exit code of the last command:

Screenshot 2024-05-03 at 21 50 21 3 4 Screenshot 2024-05-03 at 21 50 42

What can I do to fix this?

The only options I see here are user error and terminal bug.

Hi @romkatv, could you explain better what I did wrong?

I didn't mean to imply you did something wrong. Let me elaborate.

One option is that you did something different from what you think you did. That would be user error. For example, if you thought you'd changed POWERLEVEL9K_DIR_BACKGROUND but you've actually changed POWERLEVEL9K_DIR_FOREGROUND. I don't think is likely, but I wanted to list this possibility.

Another--more likely--option is that your terminal has a bug. You can verify it with the following command:

print -PC1 '%K{4}%F{255}white on blue%k%f' '%K{38}%F{255}white on teal%k%f'

The output should look like this:

image

The background on the first line may have a different color in your terminal, and that's normal. This is because colors with the numbers up to 16 are terminal-dependent. The background on the second line, and the foreground on both lines, must have exactly the same colors in all (non-buggy) terminals.

If you get grey foreground on the second line, your terminal is misbehaving. Some terminals have this unhelpful behavior on purpose with the intention of making things better. Some of those have an option in settings to turn this behavior off in their settings. It's usually called something like "minimum contrast". The ideal behind it is that the terminal will change colors if it believes that there isn't enough contrast between the foreground and the background color. I personally despise this option, for I prefer simple systems that do what I tell them to do.

You might find this FAQ helpful: https://github.com/romkatv/powerlevel10k?tab=readme-ov-file#directory-is-difficult-to-see-in-prompt-when-using-rainbow-style

My personal advice is to use Lean style. It looks better, saves horizontal space, and avoids many pitfalls around background colors.

Thanks for the clarification, @romkatv . You're right, the problem is due to the terminal. Specifically, the one integrated into VSCode. In fact, if I write what's suggested in the Apple Terminal and in the VSCode integrated Terminal, I get two different results.

Another--more likely--option is that your terminal has a bug. You can verify it with the following command:

print -PC1 '%K{4}%F{255}white on blue%k%f' '%K{38}%F{255}white on teal%k%f'

OUTPUT VSCODE:

Screenshot 2024-05-04 at 11 07 19

OUTPUT APPLE TERMINAL:

Screenshot 2024-05-04 at 11 07 06

You might find this FAQ helpful: https://github.com/romkatv/powerlevel10k?tab=readme-ov-file#directory-is-difficult-to-see-in-prompt-when-using-rainbow-style

My personal advice is to use Lean style. It looks better, saves horizontal space, and avoids many pitfalls around background colors.

I'll follow your advice and try to use the Lean style.

I'll follow your advice and try to use the Lean style.

This is a very good idea.

In addition, you might want to disable the unhelpful behavior of VSCode Terminal: https://code.visualstudio.com/docs/terminal/appearance#_minimum-contrast-ratio