Merge branch 'tab_max_length' of https://github.com/fratajczak/kitty

This commit is contained in:
Kovid Goyal 2022-11-29 14:59:18 +05:30
commit d6dcdf0751
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 16 additions and 0 deletions

View File

@ -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]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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',

View File

@ -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:

View File

@ -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'

View File

@ -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