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:
Kovid Goyal 2020-11-21 14:52:18 +05:30
parent 05eb07caf5
commit 6409786f8d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 36 additions and 0 deletions

View File

@ -7,6 +7,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
0.19.3 [future] 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 - Distribute extra pixels among all eight-blocks rather than adding them
all to the last block (:iss:`3097`) all to the last block (:iss:`3097`)

View File

@ -1459,6 +1459,37 @@ class Boss:
self._cleanup_tab_after_window_removal(tab) self._cleanup_tab_after_window_removal(tab)
target_tab.make_active() 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: def detach_window(self, *args: str) -> None:
if not args or args[0] == 'new': if not args or args[0] == 'new':
return self._move_window_to(target_os_window_id='new') return self._move_window_to(target_os_window_id='new')

View File

@ -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`. 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 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. 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.
''')) '''))