Provide access to the current keyboard mode in the tab_title_template

This commit is contained in:
Kovid Goyal 2024-04-01 22:12:49 +05:30
parent d51c342cbd
commit 23779da2dc
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 8 additions and 0 deletions

View file

@ -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 {}

View file

@ -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 <modal_mappings>` 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

View file

@ -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: