From 4b889750db2dc5b8171abb0b98cf870e7d3b1b3a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 16 Jul 2021 19:25:24 +0530 Subject: [PATCH] Add a new variable ``{num_window_groups}`` for tab_title_template See #3837 --- docs/changelog.rst | 3 +++ kitty/options/definition.py | 6 ++++-- kitty/tab_bar.py | 3 +++ kitty/tabs.py | 6 +++++- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 1c3b920f8..2f5948dbc 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -28,6 +28,9 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: Render colors in the sRGB colorspace to match other macOS terminal applications (:iss:`2249`) +- Add a new variable ``{num_window_groups}`` for the :opt:`tab_title_template` + (:iss:`3837`) + 0.21.2 [2021-06-28] ---------------------- diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 73154de20..c5d271c56 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -941,8 +941,10 @@ 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`. If you prefer to see the index as a superscript, use {sup.index}. 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 +addition you can use :code:`{layout_name}` for the current layout name, +:code:`{num_windows}` for the number of windows in the tab and +:code:`{num_window_groups}` for the number of window groups +(not counting overlay 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. If you want to style the text, you can use styling diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index ca5cc1998..35227c94f 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -23,6 +23,7 @@ class TabBarData(NamedTuple): is_active: bool needs_attention: bool num_windows: int + num_window_groups: int layout_name: str has_activity_since_last_focus: bool @@ -135,12 +136,14 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int) 'index': index, 'layout_name': tab.layout_name, 'num_windows': tab.num_windows, + 'num_window_groups': tab.num_window_groups, 'title': tab.title, } eval_locals = { 'index': index, 'layout_name': tab.layout_name, 'num_windows': tab.num_windows, + 'num_window_groups': tab.num_window_groups, 'title': tab.title, 'fmt': Formatter, 'sup': SupSub(data), diff --git a/kitty/tabs.py b/kitty/tabs.py index 4a09b09f3..b4cc6e4ab 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -577,6 +577,10 @@ class Tab: # {{{ def __len__(self) -> int: return len(self.windows) + @property + def num_window_groups(self) -> int: + return self.windows.num_groups + def __contains__(self, window: Window) -> bool: return window in self.windows @@ -874,7 +878,7 @@ class TabManager: # {{{ has_activity_since_last_focus = True ans.append(TabBarData( title, t is at, needs_attention, - len(t), t.current_layout.name or '', + len(t), t.num_window_groups, t.current_layout.name or '', has_activity_since_last_focus )) return ans