Allow using "tab" colors in the title template

Fixes #4360
This commit is contained in:
Kovid Goyal 2021-12-15 20:09:23 +05:30
parent 832f73fde9
commit 4120be3e2d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 1 deletions

View File

@ -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}`.
'''
)

View File

@ -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,