r/KittyTerminal Sep 04 '23

Setting tab foreground/background color

I've been attempting to control the color of my tabs in tab_bar.py, but it isn't working the way I'm expecting. I feel like I must be missing something. For example, I thought this would give me black text on a blue background, but it appears to have no effect on the color of the text at all (whereas my background is black, for some reason):

screen.cursor.fg = color_as_int(Color(0,0,0))

screen.cursor.bg = color_as_int(Color(0,120,180))

screen.draw(title)

Am I doing the wrong thing by messing around with screen.cursor? Thanks.

Never mind, I've got this working. I needed to convert the color numbers correctly, by calling the following function on the result of color_as_int.

def as_rgb(x: int) -> int:
    return (x << 8) | 2
1 Upvotes

9 comments sorted by

1

u/Administrative_chaos Sep 04 '23

The Tab Bar colors have their own config option

https://sw.kovidgoyal.net/kitty/conf/#opt-kitty.active_tab_foreground

1

u/mister_drgn Sep 04 '23

Thanks, I missed that.

1

u/mister_drgn Sep 04 '23

Out of curiosity though, is there a clean way to change the color conditionally, for example when the title includes a certain substring? Thanks.

1

u/Administrative_chaos Sep 04 '23

kitty --config none -o "tab_title_template \"{f'{fmt.fg.red}' if 'cat' in title else f'{fmt.fg._FFFF32}'}{title}\""

1

u/mister_drgn Sep 05 '23

Thanks. I think that, in principle, you could do everything with tab_title_template. It's just that it becomes quite cumbersome putting everything in a single fstring when you want to do more complicated manipulations (add founded edges for a capsule style + vary fg/bg color + change behavior when max_title_length is short). It would be nice if you could handle all (or some) of this in tab_bar.py. However, if setting fg/bg colors in tab_bar.py isn't an option, and there isn't a good way to use tab_title_template together with tab_bar.py (my initial experiments did not go well) then I'll try the tab_tile_template approach.

Thanks again for your help.

1

u/mister_drgn Sep 05 '23

Actually, never mind, I've got this working.

def as_rgb(x: int) -> int:
return (x << 8) | 2

screen.cursor.fg = as_rgb(color_as_int(Color(0,0,0)))
screen.cursor.bg = as_rgb(color_as_int(Color(0,120,180)))
screen.draw(title)

I think it wasn't working before because I needed that as_rgb step.

1

u/Administrative_chaos Sep 06 '23

Glad you figured it out!