Kitty: How to change the current selection's highlight color in zsh?

Created on 8 Mar 2020  路  9Comments  路  Source: kovidgoyal/kitty

Hi, and thanks for making Kitty!

Kitty seems to be using black foreground color for highlightning selected items when using zsh's tab auto-complete. This makes it really hard to read the text for current selection on dark backgrounds.

For example this gif, when hitting tab key in zsh for listing and selecting files in current directory:

kitty


However, when using gnome-terminal and doing the same, the selected file is highlighted with a white background and a black foreground:

gterm

which is easier to read.


Is it possible to change this black foregound highlight color in Kitty to something else?

I've tried setting the values for selection_foreground and selection_background but they seem to only affect colors for selections made using a mouse.

Most helpful comment

So then a reproducer would be:

kitty -o background_image=some-image.png sh -c "printf '\e[m\e[7msome_text'; read"

All 9 comments

This will be because whatever you have used to configure the colors for
zsh is incorrectly expecting the bold formatting code to make black into
gray. Some terminals still do that because they dont support bold fonts
or for legacy compatibility. Fix whatever it is you are using to set
colors and you will be fine.

Details at: https://github.com/hishamhm/htop/issues/35#issuecomment-266465736

@ritiek did you manage to sort it out?

For now I use the following trick:

theme.conf

# background color also applies to the zsh completion selection
# since my background is dark, I use a bright color for background (bright orange)
background            #ff9c00
foreground            #e0e0e0

background_image ~/Pictures/dark_background.png
# background_tint 0.5
# background_tint must be set to 0 otherwise it tints the terminal with bright orange

result:

kitty_zsh_completion

It looks good enough IMO but I miss the selection rectangle I have when no background picture is used:

kitty_zsh_completion_2

Nope. Seems like zsh doesn't offer a config option for setting this selection color. I also tried to dig in zsh's high-level sources but couldn't find anything interesting there either. This color setting is probably somewhere deep in zsh's core sources.

Its definitely not anything in zsh's core sources. I use zsh with kitty myself, and this problem does not exist. Start with any empty zshrc and bisect it to find the problem.

I should've posted a more informative comment, sorry about that!

If I completely empty my ~/.zshrc, I get no unique highlightning color when a file is selected via tab selections.

I face the original issue when ohmyzsh is enabled and I traced it to this line at fault:

zstyle ':completion:*:*:*:*:*' menu select

(actual source)

from ~/.oh-my-zsh/lib/completion.zsh.

Now if I completely empty my ~/.zshrc again (which also means no ohmyzsh plugins) but this time only put the above single culprit line in ~/.zshrc, I still end up black foreground color with selected file when using tab selections. I guess this has something to do with core zsh but then I don't really know how to debug this single line any further.

You need to figure out where zsh is getting its colors from, most likely
dircolors or something similar.

I dumped what zsh is sending (by setting the scrollback_pager to tee), and what it sends is \e[m\e[7msome_text. So it's reversing the foreground and background colors.

As far as I understand, the issue is that when background_image is set, kitty doesn't draw background color 0. So when the video is reversed, the background is still not drawn, so you end up with black text on whatever background your background image has.

So then a reproducer would be:

kitty -o background_image=some-image.png sh -c "printf '\e[m\e[7msome_text'; read"

Thank you! 5d65cdb does solve this issue for me and I get the same behaviour as gnome-terminal in original post.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Nudin picture Nudin  路  3Comments

metalelf0 picture metalelf0  路  4Comments

hujianxin picture hujianxin  路  3Comments

Jomik picture Jomik  路  4Comments

bewzaalex picture bewzaalex  路  3Comments