From 23779da2dc1c13ff433db59e401742ed87535f37 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 1 Apr 2024 22:12:49 +0530 Subject: [PATCH] Provide access to the current keyboard mode in the tab_title_template --- kitty/keys.py | 4 ++++ kitty/options/definition.py | 2 ++ kitty/tab_bar.py | 2 ++ 3 files changed, 8 insertions(+) diff --git a/kitty/keys.py b/kitty/keys.py index ecd1a4b0b..191088231 100644 --- a/kitty/keys.py +++ b/kitty/keys.py @@ -67,6 +67,10 @@ class Mappings: self.keyboard_mode_stack: List[KeyboardMode] = [] self.update_keymap(global_shortcuts) + @property + def current_keyboard_mode_name(self) -> str: + return self.keyboard_mode_stack[-1].name if self.keyboard_mode_stack else '' + def update_keymap(self, global_shortcuts:Optional[Dict[str, SingleKey]] = None) -> None: if global_shortcuts is None: global_shortcuts = self.set_cocoa_global_shortcuts(self.get_options()) if is_macos else {} diff --git a/kitty/options/definition.py b/kitty/options/definition.py index 9c6acd0f0..1cb57083a 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -1364,6 +1364,8 @@ use :code:`{sup.index}`. All data available is: :code:`active_oldest_exe` for the oldest foreground process. :code:`max_title_length` The maximum title length available. +:code:`keyboard_mode` + The name of the current :ref:`keyboard mode ` or the empty string if no keyboard mode is active. 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 diff --git a/kitty/tab_bar.py b/kitty/tab_bar.py index f7046c0c6..69a0c062f 100644 --- a/kitty/tab_bar.py +++ b/kitty/tab_bar.py @@ -240,6 +240,7 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int, max_title_length = min(max_title_length, draw_data.max_tab_title_length) ColorFormatter.draw_data = draw_data ColorFormatter.tab_data = tab + boss = get_boss() eval_locals = { 'index': index, 'layout_name': tab.layout_name, @@ -253,6 +254,7 @@ def draw_title(draw_data: DrawData, screen: Screen, tab: TabBarData, index: int, 'bell_symbol': draw_data.bell_on_tab if tab.needs_attention else '', 'activity_symbol': draw_data.tab_activity_symbol if tab.has_activity_since_last_focus else '', 'max_title_length': max_title_length, + 'keyboard_mode': boss.mappings.current_keyboard_mode_name, } template = draw_data.title_template if tab.is_active and draw_data.active_title_template is not None: