diff --git a/docs/changelog.rst b/docs/changelog.rst index c5c15f9cc..435419786 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,7 +6,11 @@ Changelog 0.13.2 [future] ------------------------------ -- Fix setting background_opacity causing window margins/padding to be slightly +- Add a new option :opt:`tab_title_template` to control how tab titles + are formatted. In particular the template can be used to display + the tab number next to the title (:iss:`1223`) + +- Fix setting :opt:`background_opacity` causing window margins/padding to be slightly different shade from background (:iss:`1221`) - Linux: Handle keyboards with a "+" key (:iss:`1224`) diff --git a/kitty/config_data.py b/kitty/config_data.py index 941feaeb6..610ad1187 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -608,6 +608,13 @@ 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`.''')) +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_foreground', '#000', option_type=to_color, long_text=_(''' Tab bar colors and styles''')) o('active_tab_background', '#eee', option_type=to_color) diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index fef66b5fb..9f5690b1d 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -16,26 +16,26 @@ from .window import calculate_gl_geometry 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_bg inactive_bg default_bg') +DrawData = namedtuple('DrawData', 'leading_spaces sep trailing_spaces bell_on_tab bell_fg alpha active_bg inactive_bg default_bg title_template') def as_rgb(x): return (x << 8) | 2 -def draw_title(draw_data, screen, tab): +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 - screen.draw(tab.title) + screen.draw(draw_data.title_template.format(title=tab.title, index=index)) -def draw_tab_with_separator(draw_data, screen, tab, before, max_title_length): +def draw_tab_with_separator(draw_data, screen, tab, before, max_title_length, index): if draw_data.leading_spaces: screen.draw(' ' * draw_data.leading_spaces) - draw_title(draw_data, screen, tab) + draw_title(draw_data, screen, tab, index) if draw_data.trailing_spaces: screen.draw(' ' * draw_data.trailing_spaces) extra = screen.cursor.x - before - max_title_length @@ -49,17 +49,17 @@ def draw_tab_with_separator(draw_data, screen, tab, before, max_title_length): return end -def draw_tab_with_fade(draw_data, screen, tab, before, max_title_length): +def draw_tab_with_fade(draw_data, screen, tab, before, max_title_length, index): tab_bg = draw_data.active_bg if tab.is_active else draw_data.inactive_bg fade_colors = [as_rgb(color_as_int(alpha_blend(tab_bg, draw_data.default_bg, alpha))) for alpha in draw_data.alpha] for bg in fade_colors: screen.cursor.bg = bg screen.draw(' ') - draw_title(draw_data, screen, tab) + draw_title(draw_data, screen, tab, index) extra = screen.cursor.x - before - max_title_length if extra > 0: screen.cursor.x = before - draw_title(draw_data, screen, tab) + draw_title(draw_data, screen, tab, index) extra = screen.cursor.x - before - max_title_length if extra > 0: screen.cursor.x -= extra + 1 @@ -81,6 +81,7 @@ 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) @@ -112,7 +113,7 @@ class TabBar: self.draw_data = DrawData( self.leading_spaces, self.sep, self.trailing_spaces, self.opts.bell_on_tab, self.bell_fg, self.opts.tab_fade, self.opts.active_tab_background, self.opts.inactive_tab_background, - self.opts.background + self.opts.background, self.opts.tab_title_template ) self.draw_func = draw_tab_with_separator if self.opts.tab_bar_style == 'separator' else draw_tab_with_fade @@ -162,12 +163,12 @@ class TabBar: cr = [] last_tab = data[-1] if data else None - for t in data: + for i, t in enumerate(data): s.cursor.bg = self.active_bg if t.is_active else 0 s.cursor.fg = self.active_fg if t.is_active else 0 s.cursor.bold, s.cursor.italic = self.active_font_style if t.is_active else self.inactive_font_style before = s.cursor.x - end = self.draw_func(self.draw_data, s, t, before, max_title_length) + end = self.draw_func(self.draw_data, s, t, before, max_title_length, i + 1) cr.append((before, end)) if s.cursor.x > s.columns - max_title_length and t is not last_tab: s.draw('…')