mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-11 19:19:35 +02:00
Add a new interactive action to set the active window title
This commit is contained in:
@@ -88,6 +88,8 @@ Detailed list of changes
|
||||
|
||||
- Shell integration: Fix ``sudo --edit`` not working and also fix completions for sudo not working in zsh (:iss:`6754`, :iss:`6771`)
|
||||
|
||||
- A new action :ac:`set_window_title` to interactively change the title of the active window
|
||||
|
||||
|
||||
0.30.1 [2023-10-05]
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@@ -1053,7 +1053,8 @@ class Boss:
|
||||
callback: Callable[..., None], # called with the answer or empty string when aborted
|
||||
window: Optional[Window] = None, # the window associated with the confirmation
|
||||
prompt: str = '> ',
|
||||
is_password: bool = False
|
||||
is_password: bool = False,
|
||||
initial_value: str = ''
|
||||
) -> None:
|
||||
result: str = ''
|
||||
|
||||
@@ -1065,6 +1066,8 @@ class Boss:
|
||||
callback(result)
|
||||
|
||||
cmd = ['--type', 'password' if is_password else 'line', '--message', msg, '--prompt', prompt]
|
||||
if initial_value:
|
||||
cmd.append('--default=' + initial_value)
|
||||
self.run_kitten_with_metadata(
|
||||
'ask', cmd, window=window, custom_callback=callback_, default_data={'response': ''}, action_on_removal=on_popup_overlay_removal
|
||||
)
|
||||
@@ -1942,12 +1945,11 @@ class Boss:
|
||||
prefilled = tab.name or tab.title
|
||||
if title in ('" "', "' '"):
|
||||
prefilled = ''
|
||||
args = [
|
||||
'--name=tab-title', '--message', _('Enter the new title for this tab below.'),
|
||||
'--default', prefilled, 'do_set_tab_title', str(tab.id)]
|
||||
self.run_kitten_with_metadata('ask', args)
|
||||
self.get_line(
|
||||
_('Enter the new title for this tab below. An empty title will cause the default title to be used.'),
|
||||
partial(self.do_set_tab_title, tab.id), window=tab.active_window, initial_value=prefilled)
|
||||
|
||||
def do_set_tab_title(self, title: str, tab_id: int) -> None:
|
||||
def do_set_tab_title(self, tab_id: int, title: str) -> None:
|
||||
tm = self.active_tab_manager
|
||||
if tm is not None:
|
||||
tab_id = int(tab_id)
|
||||
|
||||
@@ -874,9 +874,39 @@ class Window:
|
||||
if title:
|
||||
title = sanitize_title(title)
|
||||
self.override_title = title or None
|
||||
self.call_watchers(self.watchers.on_title_change, {'title': self.child_title, 'from_child': False})
|
||||
self.call_watchers(self.watchers.on_title_change, {'title': self.title, 'from_child': False})
|
||||
self.title_updated()
|
||||
|
||||
@ac(
|
||||
'win', '''
|
||||
Change the title of the active window interactively, by typing in the new title.
|
||||
If you specify an argument to this action then that is used as the title instead of asking for it.
|
||||
Use the empty string ("") to reset the title to default. Use a space (" ") to indicate that the
|
||||
prompt should not be pre-filled. For example::
|
||||
|
||||
# interactive usage
|
||||
map f1 set_window_title
|
||||
# set a specific title
|
||||
map f2 set_window_title some title
|
||||
# reset to default
|
||||
map f3 set_window_title ""
|
||||
# interactive usage without prefilled prompt
|
||||
map f3 set_window_title " "
|
||||
'''
|
||||
)
|
||||
def set_window_title(self, title: Optional[str] = None) -> None:
|
||||
if title is not None and title not in ('" "', "' '"):
|
||||
if title in ('""', "''"):
|
||||
title = ''
|
||||
self.set_title(title)
|
||||
return
|
||||
prefilled = self.title
|
||||
if title in ('" "', "' '"):
|
||||
prefilled = ''
|
||||
get_boss().get_line(
|
||||
_('Enter the new title for this window below. An empty title will cause the default title to be used.'),
|
||||
self.set_title, window=self, initial_value=prefilled)
|
||||
|
||||
def set_user_var(self, key: str, val: Optional[Union[str, bytes]]) -> None:
|
||||
key = sanitize_control_codes(key).replace('\n', ' ')
|
||||
self.user_vars.pop(key, None) # ensure key will be newest in user_vars even if already present
|
||||
|
||||
Reference in New Issue
Block a user