diff --git a/docs/changelog.rst b/docs/changelog.rst index 912ed00d7..f7fda8013 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -19,6 +19,9 @@ To update |kitty|, :doc:`follow the instructions `. - 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] -------------------- diff --git a/kitty/config_data.py b/kitty/config_data.py index 0c77f8958..34208d58d 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -716,12 +716,20 @@ entries to this list. 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''')) diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 248a735f7..cd7550c29 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -18,25 +18,32 @@ from .rgb import alpha_blend, color_from_int 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 @@ class TabBar: 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