diff --git a/docs/changelog.rst b/docs/changelog.rst index e976568b7..e37fd59b9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -57,6 +57,8 @@ Detailed list of changes - Wayland GNOME: Workaround for latest mutter release breaking full screen for semi-transparent kitty windows (:iss:`5677`) +- A new option :opt:`tab_max_length` to limit the length of tab titles + 0.26.5 [2022-11-07] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 1cb3a526e..fa88b9c0c 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -1065,6 +1065,12 @@ margin between the tab bar and the contents of the current tab. ''' ) +opt('tab_max_length', '0', option_type='positive_int', + long_text=''' +The maximum number of characters a tab title can have. +A value of zero means that no limit is applied. +''' + ) opt('tab_bar_style', 'fade', choices=('fade', 'hidden', 'powerline', 'separator', 'slant', 'custom'), ctype='!tab_bar_style', diff --git a/kitty/options/parse.py b/kitty/options/parse.py index 1ac736bbe..1d0290174 100644 --- a/kitty/options/parse.py +++ b/kitty/options/parse.py @@ -1246,6 +1246,9 @@ class Parser: def tab_fade(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['tab_fade'] = tab_fade(val) + def tab_max_length(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: + ans['tab_max_length'] = positive_int(val) + def tab_powerline_style(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: val = val.lower() if val not in self.choices_for_tab_powerline_style: diff --git a/kitty/options/types.py b/kitty/options/types.py index 4c97e4437..8351d7066 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -433,6 +433,7 @@ option_names = ( # {{{ 'tab_bar_min_tabs', 'tab_bar_style', 'tab_fade', + 'tab_max_length', 'tab_powerline_style', 'tab_separator', 'tab_switch_strategy', @@ -581,6 +582,7 @@ class Options: tab_bar_min_tabs: int = 2 tab_bar_style: choices_for_tab_bar_style = 'fade' tab_fade: typing.Tuple[float, ...] = (0.25, 0.5, 0.75, 1.0) + tab_max_length: int = 0 tab_powerline_style: choices_for_tab_powerline_style = 'angled' tab_separator: str = ' ┇' tab_switch_strategy: choices_for_tab_switch_strategy = 'previous' diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 68003784f..a125d0ff0 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -514,6 +514,7 @@ class TabBar: self.align = self.align_with_factor else: self.align = lambda: None + self.max_tab_length = opts.tab_max_length def patch_colors(self, spec: Dict[str, Optional[int]]) -> None: opts = get_options() @@ -616,6 +617,8 @@ class TabBar: unconstrained_tab_length = max(1, s.columns - 2) ideal_tab_lengths = [i for i in range(len(data))] default_max_tab_length = max(1, (s.columns // max(1, len(data))) - 1) + if self.max_tab_length >= 1: + default_max_tab_length = min(self.max_tab_length, default_max_tab_length) max_tab_lengths = [default_max_tab_length for _ in range(len(data))] active_idx = 0 extra = 0