From 6409786f8d5075018bf0a40b40ba045ce01d3f4b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 21 Nov 2020 14:52:18 +0530 Subject: [PATCH] Add a new mappable `select_tab` action to choose a tab to switch to even when the tab bar is hidden Fixes #3115 --- docs/changelog.rst | 3 +++ kitty/boss.py | 31 +++++++++++++++++++++++++++++++ kitty/config_data.py | 2 ++ 3 files changed, 36 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index b8d0edc4d..a1a88c9d4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,9 @@ To update |kitty|, :doc:`follow the instructions `. 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`) diff --git a/kitty/boss.py b/kitty/boss.py index 73bcad7ae..f55338644 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -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') diff --git a/kitty/config_data.py b/kitty/config_data.py index 3b010a7cb..db95e7585 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -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. '''))