From 2a3cc7164173de1452890fd5238b2b79b1d15d61 Mon Sep 17 00:00:00 2001 From: Sam Foster Date: Tue, 23 Feb 2021 21:07:01 -0600 Subject: [PATCH] Made powerline tab_bar_style have different display options --- kitty/config_data.py | 5 +++++ kitty/tab_bar.py | 21 ++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/kitty/config_data.py b/kitty/config_data.py index e0cba08a2..dffa5c57a 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -907,6 +907,11 @@ 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_powerline_style', 'angled', option_type=choices('angled', 'slanted', 'round'), long_text=_(''' +The powerline separator style between tabs in the tab bar when using :code:`powerline` +as the :opt:`tab_bar_style`, can be one of: :code:`angled`, :code:`slanted`, or :code:`round`. +''')) + def tab_activity_symbol(x: str) -> Optional[str]: if x == 'none': diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 0fdab9e46..74b0477fe 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -42,6 +42,7 @@ class DrawData(NamedTuple): title_template: str active_title_template: Optional[str] tab_activity_symbol: Optional[str] + powerline_style: str def as_rgb(x: int) -> int: @@ -186,13 +187,22 @@ def draw_tab_with_powerline(draw_data: DrawData, screen: Screen, tab: TabBarData inactive_bg = as_rgb(color_as_int(draw_data.inactive_bg)) default_bg = as_rgb(color_as_int(draw_data.default_bg)) + separator_symbol = '' + separator_alt_symbol = '' + if draw_data.powerline_style == 'slanted': + separator_symbol = '' + separator_alt_symbol = '╱' + elif draw_data.powerline_style == 'round': + separator_symbol = '' + separator_alt_symbol = '' + min_title_length = 1 + 2 if screen.cursor.x + min_title_length >= screen.columns: screen.cursor.x -= 2 screen.cursor.bg = default_bg screen.cursor.fg = inactive_bg - screen.draw(' ') + screen.draw('{} '.format(separator_symbol)) return screen.cursor.x start_draw = 2 @@ -200,7 +210,7 @@ def draw_tab_with_powerline(draw_data: DrawData, screen: Screen, tab: TabBarData screen.cursor.x -= 2 screen.cursor.fg = inactive_bg screen.cursor.bg = tab_bg - screen.draw(' ') + screen.draw('{} '.format(separator_symbol)) screen.cursor.fg = tab_fg elif screen.cursor.x == 0: screen.cursor.bg = tab_bg @@ -224,9 +234,9 @@ def draw_tab_with_powerline(draw_data: DrawData, screen: Screen, tab: TabBarData screen.cursor.bg = default_bg else: screen.cursor.bg = inactive_bg - screen.draw('') + screen.draw(separator_symbol) else: - screen.draw(' ') + screen.draw(' {}'.format(separator_alt_symbol)) end = screen.cursor.x if end < screen.columns: @@ -273,7 +283,8 @@ class TabBar: 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.active_tab_title_template, - self.opts.tab_activity_symbol + self.opts.tab_activity_symbol, + self.opts.tab_powerline_style ) if self.opts.tab_bar_style == 'separator': self.draw_func = draw_tab_with_separator