From 28fc9c69da53c59360e145e671e173975afba6b5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 9 May 2020 08:00:17 +0530 Subject: [PATCH] Allow showing the name of the current layout and the number of windows in tab titles Fixes #2634 --- docs/changelog.rst | 3 +++ kitty/config_data.py | 5 +++++ kitty/tab_bar.py | 4 +++- kitty/tabs.py | 19 ++++++++++++++----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 6376e410e..723976c9e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,9 @@ To update |kitty|, :doc:`follow the instructions `. 0.17.4 [future] -------------------- +- Allow showing the name of the current layout and the number of windows + in tab titles (:iss:`2634`) + - macOS: Fix a regression in the previous release that caused ligatures to be not be centered horizontally (:iss:`2591`) diff --git a/kitty/config_data.py b/kitty/config_data.py index 92547e7de..f5f29b8dd 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -870,6 +870,11 @@ A template to render the tab title. The default just renders the title. If you wish to include the tab-index as well, use something like: :code:`{index}: {title}`. Useful if you have shortcuts mapped for :code:`goto_tab N`. +In addition you can use :code:`{layout_name}` for the current +layout name and :code:`{num_windows}` for the number of windows +in the tab. Note that formatting is done by Python's string formatting +machinery, so you can use, for instance, :code:`{layout_name[:2].upper()}` to +show only the first two letters of the layout name, upper-cased. ''')) o('active_tab_title_template', 'none', option_type=active_tab_title_template, long_text=_(''' Template to use for active tabs, if not specified falls back diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index 69d82141e..640c2daaa 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -21,6 +21,8 @@ class TabBarData(NamedTuple): title: str is_active: bool needs_attention: bool + num_windows: int + layout_name: str class DrawData(NamedTuple): @@ -56,7 +58,7 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int) if tab.is_active and draw_data.active_title_template is not None: template = draw_data.active_title_template try: - title = template.format(title=tab.title, index=index) + title = template.format(title=tab.title, index=index, layout_name=tab.layout_name, num_windows=tab.num_windows) except Exception as e: if template not in template_failures: template_failures.add(template) diff --git a/kitty/tabs.py b/kitty/tabs.py index cd0b320cd..436b3da92 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -138,6 +138,7 @@ class Tab: # {{{ self._last_used_layout = self._current_layout_name self.current_layout = self.create_layout_object(layout_name) self._current_layout_name = layout_name + self.mark_tab_bar_dirty() def startup(self, session_tab: 'SessionTab') -> None: for cmd in session_tab.windows: @@ -183,10 +184,13 @@ class Tab: # {{{ old_active_window.focus_changed(False) if new_active_window is not None: new_active_window.focus_changed(True) - tm = self.tab_manager_ref() - if tm is not None: - self.relayout_borders() - tm.mark_tab_bar_dirty() + self.relayout_borders() + self.mark_tab_bar_dirty() + + def mark_tab_bar_dirty(self) -> None: + tm = self.tab_manager_ref() + if tm is not None: + tm.mark_tab_bar_dirty() @property def active_window(self) -> Optional[Window]: @@ -330,6 +334,7 @@ class Tab: # {{{ def _add_window(self, window: Window, location: Optional[str] = None) -> None: self.active_window_idx = self.current_layout.add_window(self.windows, window, self.active_window_idx, location) self.relayout_borders() + self.mark_tab_bar_dirty() def new_window( self, @@ -431,6 +436,7 @@ class Tab: # {{{ else: self.active_window_idx = active_window_idx self.relayout_borders() + self.mark_tab_bar_dirty() active_window = self.active_window if active_window: self.title_changed(active_window) @@ -804,7 +810,10 @@ class TabManager: # {{{ if w.needs_attention: needs_attention = True break - ans.append(TabBarData(title, t is at, needs_attention)) + ans.append(TabBarData( + title, t is at, needs_attention, + len(t), t.current_layout.name or '' + )) return ans def activate_tab_at(self, x: int) -> None: