Change the new option to limit tab title lengths to apply to the length of the title, as documented, nit the full tab
This commit is contained in:
parent
6f66bbd424
commit
5c50e3869c
@ -57,7 +57,7 @@ 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
|
||||
- A new option :opt:`tab_title_max_length` to limit the length of tab titles
|
||||
|
||||
|
||||
0.26.5 [2022-11-07]
|
||||
|
||||
@ -1065,7 +1065,7 @@ margin between the tab bar and the contents of the current tab.
|
||||
'''
|
||||
)
|
||||
|
||||
opt('tab_max_length', '0', option_type='positive_int',
|
||||
opt('tab_title_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.
|
||||
|
||||
6
kitty/options/parse.py
generated
6
kitty/options/parse.py
generated
@ -1246,9 +1246,6 @@ 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:
|
||||
@ -1268,6 +1265,9 @@ class Parser:
|
||||
|
||||
choices_for_tab_switch_strategy = frozenset(('last', 'left', 'previous', 'right'))
|
||||
|
||||
def tab_title_max_length(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['tab_title_max_length'] = positive_int(val)
|
||||
|
||||
def tab_title_template(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['tab_title_template'] = tab_title_template(val)
|
||||
|
||||
|
||||
6
kitty/options/types.py
generated
6
kitty/options/types.py
generated
@ -433,10 +433,10 @@ option_names = ( # {{{
|
||||
'tab_bar_min_tabs',
|
||||
'tab_bar_style',
|
||||
'tab_fade',
|
||||
'tab_max_length',
|
||||
'tab_powerline_style',
|
||||
'tab_separator',
|
||||
'tab_switch_strategy',
|
||||
'tab_title_max_length',
|
||||
'tab_title_template',
|
||||
'term',
|
||||
'touch_scroll_multiplier',
|
||||
@ -489,7 +489,7 @@ class Options:
|
||||
clear_all_shortcuts: bool = False
|
||||
click_interval: float = -1.0
|
||||
clipboard_control: typing.Tuple[str, ...] = ('write-clipboard', 'write-primary', 'read-clipboard-ask', 'read-primary-ask')
|
||||
clipboard_max_size: float = 64.0
|
||||
clipboard_max_size: float = 512.0
|
||||
clone_source_strategies: typing.FrozenSet[str] = frozenset({'conda', 'env_var', 'path', 'venv'})
|
||||
close_on_child_death: bool = False
|
||||
command_on_bell: typing.List[str] = ['none']
|
||||
@ -582,10 +582,10 @@ 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'
|
||||
tab_title_max_length: int = 0
|
||||
tab_title_template: str = '{fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{title}'
|
||||
term: str = 'xterm-kitty'
|
||||
touch_scroll_multiplier: float = 1.0
|
||||
|
||||
@ -53,6 +53,7 @@ class DrawData(NamedTuple):
|
||||
tab_activity_symbol: str
|
||||
powerline_style: PowerlineStyle
|
||||
tab_bar_edge: EdgeLiteral
|
||||
max_tab_title_length: int
|
||||
|
||||
def tab_fg(self, tab: TabBarData) -> int:
|
||||
if tab.is_active:
|
||||
@ -285,6 +286,8 @@ def draw_tab_with_slant(
|
||||
else:
|
||||
draw_sep(left_sep)
|
||||
screen.draw(' ')
|
||||
if draw_data.max_tab_title_length > 0:
|
||||
max_tab_length = min(draw_data.max_tab_title_length, max_tab_length)
|
||||
draw_title(draw_data, screen, tab, index, max_tab_length)
|
||||
extra = screen.cursor.x - before - max_tab_length
|
||||
if extra >= 0:
|
||||
@ -306,6 +309,8 @@ def draw_tab_with_separator(
|
||||
) -> int:
|
||||
if draw_data.leading_spaces:
|
||||
screen.draw(' ' * draw_data.leading_spaces)
|
||||
if draw_data.max_tab_title_length > 0:
|
||||
max_tab_length = min(draw_data.max_tab_title_length, max_tab_length)
|
||||
draw_title(draw_data, screen, tab, index, max_tab_length)
|
||||
trailing_spaces = min(max_tab_length - 1, draw_data.trailing_spaces)
|
||||
max_tab_length -= trailing_spaces
|
||||
@ -337,6 +342,8 @@ def draw_tab_with_fade(
|
||||
screen.cursor.bg = bg
|
||||
screen.draw(' ')
|
||||
screen.cursor.bg = orig_bg
|
||||
if draw_data.max_tab_title_length > 0:
|
||||
max_tab_length = min(draw_data.max_tab_title_length, max_tab_length)
|
||||
draw_title(draw_data, screen, tab, index, max(0, max_tab_length - 8))
|
||||
extra = screen.cursor.x - before - max_tab_length
|
||||
if extra > 0:
|
||||
@ -389,6 +396,8 @@ def draw_tab_with_powerline(
|
||||
start_draw = 1
|
||||
|
||||
screen.cursor.bg = tab_bg
|
||||
if draw_data.max_tab_title_length > 0:
|
||||
max_tab_length = min(draw_data.max_tab_title_length, max_tab_length)
|
||||
if min_title_length >= max_tab_length:
|
||||
screen.draw('…')
|
||||
else:
|
||||
@ -495,7 +504,8 @@ class TabBar:
|
||||
opts.active_tab_title_template,
|
||||
opts.tab_activity_symbol,
|
||||
opts.tab_powerline_style,
|
||||
'top' if opts.tab_bar_edge == 1 else 'bottom'
|
||||
'top' if opts.tab_bar_edge == 1 else 'bottom',
|
||||
opts.tab_title_max_length,
|
||||
)
|
||||
ts = opts.tab_bar_style
|
||||
if ts == 'separator':
|
||||
@ -514,7 +524,6 @@ 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()
|
||||
@ -617,8 +626,6 @@ 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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user