Add a new mappable select_tab action to choose a tab to switch to even when the tab bar is hidden
Fixes #3115
This commit is contained in:
parent
05eb07caf5
commit
6409786f8d
@ -7,6 +7,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
||||
0.19.3 [future]
|
||||
-------------------
|
||||
|
||||
- Add a new mappable `select_tab` action to choose a tab to switch to even
|
||||
when the tab bar is hidden (:iss:`3115`)
|
||||
|
||||
- Distribute extra pixels among all eight-blocks rather than adding them
|
||||
all to the last block (:iss:`3097`)
|
||||
|
||||
|
||||
@ -1459,6 +1459,37 @@ class Boss:
|
||||
self._cleanup_tab_after_window_removal(tab)
|
||||
target_tab.make_active()
|
||||
|
||||
def select_tab(self) -> None:
|
||||
lines = ['Choose a tab to switch to', '']
|
||||
fmt = ': {1}'
|
||||
tab_id_map: Dict[int, Optional[Union[str, int]]] = {}
|
||||
current_tab = self.active_tab
|
||||
done_tab_id: Optional[Union[str, int]] = None
|
||||
|
||||
for i, tab in enumerate(self.all_tabs):
|
||||
if tab is not current_tab:
|
||||
tab_id_map[len(tab_id_map)] = tab.id
|
||||
lines.append(fmt.format(i + 1, tab.title))
|
||||
|
||||
def done(data: Dict[str, Any], target_window_id: int, self: Boss) -> None:
|
||||
nonlocal done_tab_id
|
||||
done_tab_id = tab_id_map[int(data['groupdicts'][0]['index'])]
|
||||
|
||||
def done2(target_window_id: int, self: Boss) -> None:
|
||||
tab_id = done_tab_id
|
||||
if tab_id is not None:
|
||||
for i, tab in enumerate(self.all_tabs):
|
||||
if tab.id == tab_id:
|
||||
self.set_active_tab(tab)
|
||||
break
|
||||
|
||||
self._run_kitten(
|
||||
'hints', args=(
|
||||
'--ascending', '--customize-processing=::import::kitty.choose_entry',
|
||||
r'--regex=(?m)^:\s+.+$',
|
||||
), input_data='\r\n'.join(lines).encode('utf-8'), custom_callback=done, action_on_removal=done2
|
||||
)
|
||||
|
||||
def detach_window(self, *args: str) -> None:
|
||||
if not args or args[0] == 'new':
|
||||
return self._move_window_to(target_os_window_id='new')
|
||||
|
||||
@ -862,6 +862,8 @@ o('tab_bar_style', 'fade', option_type=choices('fade', 'separator', 'powerline',
|
||||
The tab bar style, can be one of: :code:`fade`, :code:`separator`, :code:`powerline`, or :code:`hidden`.
|
||||
In the fade style, each tab's edges fade into the background color, in the separator style, tabs are
|
||||
separated by a configurable separator, and the powerline shows the tabs as a continuous line.
|
||||
If you use the hidden style, you might want to create a mapping for the :code:`select_tab` action which
|
||||
presents you with a list of tabs and allows for easy switching to a tab.
|
||||
'''))
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user