From 4120be3e2dc470dd498b3f7b3008a03c29501b26 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Dec 2021 20:09:23 +0530 Subject: [PATCH] Allow using "tab" colors in the title template Fixes #4360 --- kitty/options/definition.py | 2 +- kitty/tab_bar.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 714f6e6d3..110b1e68f 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -1072,7 +1072,7 @@ is done by Python's string formatting machinery, so you can use, for instance, layout name, upper-cased. If you want to style the text, you can use styling directives, for example: :code:`{fmt.fg.red}red{fmt.fg.default}normal{fmt.bg._00FF00}green -bg{fmt.bg.default}`. Similarly, for bold and italic: +bg{fmt.bg.tab}`. Similarly, for bold and italic: :code:`{fmt.bold}bold{fmt.nobold}normal{fmt.italic}italic{fmt.noitalic}`. ''' ) diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 9e121c2f6..4b568f988 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -90,6 +90,9 @@ def compile_template(template: str) -> Any: class ColorFormatter: + draw_data: DrawData + tab: TabBarData + def __init__(self, which: str): self.which = which @@ -97,6 +100,9 @@ class ColorFormatter: q = name if q == 'default': ans = '9' + elif q == 'tab': + col = color_from_int((self.draw_data.tab_bg if self.which == '4' else self.draw_data.tab_fg)(self.tab)) + ans = '8' + color_as_sgr(col) else: if name.startswith('_'): q = '#' + name[1:] @@ -169,6 +175,8 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int) 'num_window_groups': tab.num_window_groups, 'title': tab.title, } + ColorFormatter.draw_data = draw_data + ColorFormatter.tab = tab eval_locals = { 'index': index, 'layout_name': tab.layout_name,