mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 02:02:14 +02:00
Add a new option 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 Merge branch 'tab-title-index' of https://github.com/nerdrew/kitty
This commit is contained in:
@@ -6,7 +6,11 @@ Changelog
|
|||||||
0.13.2 [future]
|
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`)
|
different shade from background (:iss:`1221`)
|
||||||
|
|
||||||
- Linux: Handle keyboards with a "+" key (:iss:`1224`)
|
- Linux: Handle keyboards with a "+" key (:iss:`1224`)
|
||||||
|
|||||||
@@ -608,6 +608,13 @@ entries to this list.
|
|||||||
o('tab_separator', '"{}"'.format(default_tab_separator), option_type=tab_separator, long_text=_('''
|
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`.'''))
|
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=_('''
|
o('active_tab_foreground', '#000', option_type=to_color, long_text=_('''
|
||||||
Tab bar colors and styles'''))
|
Tab bar colors and styles'''))
|
||||||
o('active_tab_background', '#eee', option_type=to_color)
|
o('active_tab_background', '#eee', option_type=to_color)
|
||||||
|
|||||||
@@ -16,26 +16,26 @@ from .window import calculate_gl_geometry
|
|||||||
from .rgb import alpha_blend, color_from_int
|
from .rgb import alpha_blend, color_from_int
|
||||||
|
|
||||||
TabBarData = namedtuple('TabBarData', 'title is_active needs_attention')
|
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):
|
def as_rgb(x):
|
||||||
return (x << 8) | 2
|
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:
|
if tab.needs_attention and draw_data.bell_on_tab:
|
||||||
fg = screen.cursor.fg
|
fg = screen.cursor.fg
|
||||||
screen.cursor.fg = draw_data.bell_fg
|
screen.cursor.fg = draw_data.bell_fg
|
||||||
screen.draw('🔔 ')
|
screen.draw('🔔 ')
|
||||||
screen.cursor.fg = fg
|
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:
|
if draw_data.leading_spaces:
|
||||||
screen.draw(' ' * 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:
|
if draw_data.trailing_spaces:
|
||||||
screen.draw(' ' * draw_data.trailing_spaces)
|
screen.draw(' ' * draw_data.trailing_spaces)
|
||||||
extra = screen.cursor.x - before - max_title_length
|
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
|
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
|
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]
|
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:
|
for bg in fade_colors:
|
||||||
screen.cursor.bg = bg
|
screen.cursor.bg = bg
|
||||||
screen.draw(' ')
|
screen.draw(' ')
|
||||||
draw_title(draw_data, screen, tab)
|
draw_title(draw_data, screen, tab, index)
|
||||||
extra = screen.cursor.x - before - max_title_length
|
extra = screen.cursor.x - before - max_title_length
|
||||||
if extra > 0:
|
if extra > 0:
|
||||||
screen.cursor.x = before
|
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
|
extra = screen.cursor.x - before - max_title_length
|
||||||
if extra > 0:
|
if extra > 0:
|
||||||
screen.cursor.x -= extra + 1
|
screen.cursor.x -= extra + 1
|
||||||
@@ -81,6 +81,7 @@ class TabBar:
|
|||||||
def __init__(self, os_window_id, opts):
|
def __init__(self, os_window_id, opts):
|
||||||
self.os_window_id = os_window_id
|
self.os_window_id = os_window_id
|
||||||
self.opts = opts
|
self.opts = opts
|
||||||
|
draw_title.template = opts.tab_title_template
|
||||||
self.num_tabs = 1
|
self.num_tabs = 1
|
||||||
self.margin_width = pt_to_px(self.opts.tab_bar_margin_width, self.os_window_id)
|
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)
|
self.cell_width, cell_height = cell_size_for_window(self.os_window_id)
|
||||||
@@ -112,7 +113,7 @@ class TabBar:
|
|||||||
self.draw_data = DrawData(
|
self.draw_data = DrawData(
|
||||||
self.leading_spaces, self.sep, self.trailing_spaces, self.opts.bell_on_tab, self.bell_fg,
|
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.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
|
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 = []
|
cr = []
|
||||||
last_tab = data[-1] if data else None
|
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.bg = self.active_bg if t.is_active else 0
|
||||||
s.cursor.fg = self.active_fg 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
|
s.cursor.bold, s.cursor.italic = self.active_font_style if t.is_active else self.inactive_font_style
|
||||||
before = s.cursor.x
|
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))
|
cr.append((before, end))
|
||||||
if s.cursor.x > s.columns - max_title_length and t is not last_tab:
|
if s.cursor.x > s.columns - max_title_length and t is not last_tab:
|
||||||
s.draw('…')
|
s.draw('…')
|
||||||
|
|||||||
Reference in New Issue
Block a user