mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-21 11:39:57 +03:00
Add a new option active_tab_title_template to specify a different template for active tab titles
Fixes #2198
This commit is contained in:
parent
f59afff1d1
commit
2487f18f24
@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
- Add a new option :opt:`tab_bar_background` to specify a different color
|
||||
for the tab bar (:iss:`2198`)
|
||||
|
||||
- Add a new option :opt:`active_tab_title_template` to specify a different
|
||||
template for active tab titles (:iss:`2198`)
|
||||
|
||||
0.15.0 [2019-11-27]
|
||||
--------------------
|
||||
|
||||
|
@ -716,12 +716,20 @@ def tab_fade(x):
|
||||
o('tab_separator', '"{}"'.format(default_tab_separator), option_type=tab_separator, long_text=_('''
|
||||
The separator between tabs in the tab bar when using :code:`separator` as the :opt:`tab_bar_style`.'''))
|
||||
|
||||
|
||||
def active_tab_title_template(x):
|
||||
return None if x == 'none' else x
|
||||
|
||||
|
||||
o('tab_title_template', '{title}', long_text=_('''
|
||||
A template to render the tab title. The default just renders
|
||||
the title. If you wish to include the tab-index as well,
|
||||
use something like: :code:`{index}: {title}`. Useful
|
||||
if you have shortcuts mapped for :code:`goto_tab N`.
|
||||
'''))
|
||||
o('active_tab_title_template', 'none', option_type=active_tab_title_template, long_text=_('''
|
||||
Template to use for active tabs, if not specified falls back
|
||||
to :opt:`tab_title_template`.'''))
|
||||
|
||||
o('active_tab_foreground', '#000', option_type=to_color, long_text=_('''
|
||||
Tab bar colors and styles'''))
|
||||
|
@ -18,25 +18,32 @@
|
||||
TabBarData = namedtuple('TabBarData', 'title is_active needs_attention')
|
||||
DrawData = namedtuple(
|
||||
'DrawData', 'leading_spaces sep trailing_spaces bell_on_tab'
|
||||
' bell_fg alpha active_fg active_bg inactive_fg inactive_bg default_bg title_template')
|
||||
' bell_fg alpha active_fg active_bg inactive_fg inactive_bg'
|
||||
' default_bg title_template active_title_template')
|
||||
|
||||
|
||||
def as_rgb(x):
|
||||
return (x << 8) | 2
|
||||
|
||||
|
||||
template_failures = set()
|
||||
|
||||
|
||||
def draw_title(draw_data, screen, tab, index):
|
||||
if tab.needs_attention and draw_data.bell_on_tab:
|
||||
fg = screen.cursor.fg
|
||||
screen.cursor.fg = draw_data.bell_fg
|
||||
screen.draw('🔔 ')
|
||||
screen.cursor.fg = fg
|
||||
template = draw_data.title_template
|
||||
if tab.is_active and draw_data.active_title_template is not None:
|
||||
template = draw_data.active_title_template
|
||||
try:
|
||||
title = draw_data.title_template.format(title=tab.title, index=index)
|
||||
title = template.format(title=tab.title, index=index)
|
||||
except Exception as e:
|
||||
if not hasattr(draw_title, 'template_failure_reported'):
|
||||
draw_title.template_failure_reported = True
|
||||
log_error('Invalid tab title template: "{}" with error: {}'.format(draw_data.title_template, e))
|
||||
if template not in template_failures:
|
||||
template_failures.add(template)
|
||||
log_error('Invalid tab title template: "{}" with error: {}'.format(template, e))
|
||||
title = tab.title
|
||||
screen.draw(title)
|
||||
|
||||
@ -144,7 +151,6 @@ class TabBar:
|
||||
def __init__(self, os_window_id, opts):
|
||||
self.os_window_id = os_window_id
|
||||
self.opts = opts
|
||||
draw_title.template = opts.tab_title_template
|
||||
self.num_tabs = 1
|
||||
self.margin_width = pt_to_px(self.opts.tab_bar_margin_width, self.os_window_id)
|
||||
self.cell_width, cell_height = cell_size_for_window(self.os_window_id)
|
||||
@ -177,7 +183,8 @@ def __init__(self, os_window_id, opts):
|
||||
self.leading_spaces, self.sep, self.trailing_spaces, self.opts.bell_on_tab, self.bell_fg,
|
||||
self.opts.tab_fade, self.opts.active_tab_foreground, self.opts.active_tab_background,
|
||||
self.opts.inactive_tab_foreground, self.opts.inactive_tab_background,
|
||||
self.opts.tab_bar_background or self.opts.background, self.opts.tab_title_template
|
||||
self.opts.tab_bar_background or self.opts.background, self.opts.tab_title_template,
|
||||
self.opts.active_tab_title_template
|
||||
)
|
||||
if self.opts.tab_bar_style == 'separator':
|
||||
self.draw_func = draw_tab_with_separator
|
||||
|
Loading…
Reference in New Issue
Block a user