Add window titles to various ask kitten invocations

This commit is contained in:
Kovid Goyal
2023-10-20 13:36:02 +05:30
parent 321f1a6650
commit beb18cc250
5 changed files with 28 additions and 11 deletions

View File

@@ -362,12 +362,15 @@ func GetChoices(o *Options) (response string, err error) {
if hidden_text != "" && message != "" { if hidden_text != "" && message != "" {
message = message[:hidden_text_start_pos] + hidden_text + message[hidden_text_end_pos:] message = message[:hidden_text_start_pos] + hidden_text + message[hidden_text_end_pos:]
hidden_text = "" hidden_text = ""
draw_screen() _ = draw_screen()
} }
} }
lp.OnInitialize = func() (string, error) { lp.OnInitialize = func() (string, error) {
lp.SetCursorVisible(false) lp.SetCursorVisible(false)
if o.Title != "" {
lp.SetWindowTitle(o.Title)
}
return "", draw_screen() return "", draw_screen()
} }

View File

@@ -30,6 +30,11 @@ The name for this question. Used to store history of previous answers which can
be used for completions and via the browse history readline bindings. be used for completions and via the browse history readline bindings.
--title --window-title
The title for the window in which the question is displayed. Only implemented
for yesno and choices types.
--choice -c --choice -c
type=list type=list
dest=choices dest=choices

View File

@@ -129,6 +129,7 @@ func Run(args []string) (rc int, err error) {
} }
lp.OnInitialize = func() (string, error) { lp.OnInitialize = func() (string, error) {
lp.SetWindowTitle("kitty mouse features demo")
lp.SetCursorVisible(false) lp.SetCursorVisible(false)
draw_screen() draw_screen()
return "", nil return "", nil

View File

@@ -678,7 +678,7 @@ class Boss:
), dim=True, italic=True)), ), dim=True, italic=True)),
partial(self.remote_cmd_permission_received, pcmd, wid, peer_id, self_window), partial(self.remote_cmd_permission_received, pcmd, wid, peer_id, self_window),
'a;green:Allow request', 'p;yellow:Allow password', 'r;magenta:Deny request', 'd;red:Deny password', 'a;green:Allow request', 'p;yellow:Allow password', 'r;magenta:Deny request', 'd;red:Deny password',
window=window, default='a', hidden_text=hidden_text window=window, default='a', hidden_text=hidden_text, title=_('Allow remote control?'),
) )
if overlay_window is None: if overlay_window is None:
return False return False
@@ -950,7 +950,7 @@ class Boss:
msg = _('Are you sure you want to close this window?') msg = _('Are you sure you want to close this window?')
if window.has_running_program: if window.has_running_program:
msg += ' ' + _('It is running a program.') msg += ' ' + _('It is running a program.')
self.confirm(msg, self.handle_close_window_confirmation, window.id, window=window) self.confirm(msg, self.handle_close_window_confirmation, window.id, window=window, title=_('Close window?'))
else: else:
self.mark_window_for_close(window) self.mark_window_for_close(window)
@@ -980,6 +980,7 @@ class Boss:
window: Optional[Window] = None, # the window associated with the confirmation window: Optional[Window] = None, # the window associated with the confirmation
confirm_on_cancel: bool = False, # on closing window confirm_on_cancel: bool = False, # on closing window
confirm_on_accept: bool = True, # on pressing enter confirm_on_accept: bool = True, # on pressing enter
title: str = '' # window title
) -> Window: ) -> Window:
result: bool = False result: bool = False
@@ -990,9 +991,11 @@ class Boss:
def on_popup_overlay_removal(wid: int, boss: Boss) -> None: def on_popup_overlay_removal(wid: int, boss: Boss) -> None:
callback(result, *args) callback(result, *args)
cmd = ['--type=yesno', '--message', msg, '--default', 'y' if confirm_on_accept else 'n']
if title:
cmd += ['--title', title]
w = self.run_kitten_with_metadata( w = self.run_kitten_with_metadata(
'ask', ['--type=yesno', '--message', msg, '--default', 'y' if confirm_on_accept else 'n'], 'ask', cmd, window=window, custom_callback=callback_, action_on_removal=on_popup_overlay_removal,
window=window, custom_callback=callback_, action_on_removal=on_popup_overlay_removal,
default_data={'response': 'y' if confirm_on_cancel else 'n'}) default_data={'response': 'y' if confirm_on_cancel else 'n'})
assert isinstance(w, Window) assert isinstance(w, Window)
return w return w
@@ -1006,6 +1009,7 @@ class Boss:
hidden_text: str = '', # text to hide in the message hidden_text: str = '', # text to hide in the message
hidden_text_placeholder: str = 'HIDDEN_TEXT_PLACEHOLDER', # placeholder text to insert in to message hidden_text_placeholder: str = 'HIDDEN_TEXT_PLACEHOLDER', # placeholder text to insert in to message
unhide_key: str = 'u', # key to press to unhide hidden text unhide_key: str = 'u', # key to press to unhide hidden text
title: str = '' # window title
) -> Optional[Window]: ) -> Optional[Window]:
result: str = '' result: str = ''
@@ -1025,6 +1029,8 @@ class Boss:
input_data = hidden_text input_data = hidden_text
else: else:
input_data = None input_data = None
if title:
cmd += ['--title', title]
def on_popup_overlay_removal(wid: int, boss: Boss) -> None: def on_popup_overlay_removal(wid: int, boss: Boss) -> None:
callback(result) callback(result)
@@ -1077,7 +1083,7 @@ class Boss:
w = self.confirm(ngettext('Are you sure you want to close this tab, it has one window running?', w = self.confirm(ngettext('Are you sure you want to close this tab, it has one window running?',
'Are you sure you want to close this tab, it has {} windows running?', num).format(num), 'Are you sure you want to close this tab, it has {} windows running?', num).format(num),
self.handle_close_tab_confirmation, tab.id, self.handle_close_tab_confirmation, tab.id,
window=tab.active_window, window=tab.active_window, title=_('Close tab?'),
) )
tab.confirm_close_window_id = w.id tab.confirm_close_window_id = w.id
@@ -1681,7 +1687,7 @@ class Boss:
ngettext('Are you sure you want to close this OS window, it has one window running?', ngettext('Are you sure you want to close this OS window, it has one window running?',
'Are you sure you want to close this OS window, it has {} windows running', num).format(num), 'Are you sure you want to close this OS window, it has {} windows running', num).format(num),
self.handle_close_os_window_confirmation, os_window_id, self.handle_close_os_window_confirmation, os_window_id,
window=tm.active_window, window=tm.active_window, title=_('Close OS window'),
) )
tm.confirm_close_window_id = w.id tm.confirm_close_window_id = w.id
@@ -1737,7 +1743,7 @@ class Boss:
ngettext('Are you sure you want to quit kitty, it has one window running?', ngettext('Are you sure you want to quit kitty, it has one window running?',
'Are you sure you want to quit kitty, it has {} windows running?', num).format(num), 'Are you sure you want to quit kitty, it has {} windows running?', num).format(num),
self.handle_quit_confirmation, self.handle_quit_confirmation,
window=tm.active_window, window=tm.active_window, title=_('Quit kitty?'),
) )
self.quit_confirmation_window_id = w.id self.quit_confirmation_window_id = w.id
set_application_quit_request(CLOSE_BEING_CONFIRMED) set_application_quit_request(CLOSE_BEING_CONFIRMED)

View File

@@ -950,7 +950,7 @@ class Window:
'What would you like to do with this URL:\n' + styled(sanitize_url_for_dispay_to_user(url), fg='yellow'), 'What would you like to do with this URL:\n' + styled(sanitize_url_for_dispay_to_user(url), fg='yellow'),
partial(self.hyperlink_open_confirmed, url, cwd), partial(self.hyperlink_open_confirmed, url, cwd),
'o:Open', 'c:Copy to clipboard', 'n;red:Nothing', default='o', 'o:Open', 'c:Copy to clipboard', 'n;red:Nothing', default='o',
window=self, window=self, title=_('Hyperlink activated'),
) )
return return
get_boss().open_url(url, cwd=cwd) get_boss().open_url(url, cwd=cwd)
@@ -1205,6 +1205,7 @@ class Window:
'A program running in this window wants to clone it into another window.' 'A program running in this window wants to clone it into another window.'
' Allow it do so, once?'), ' Allow it do so, once?'),
partial(self.handle_remote_clone_confirmation, cdata), window=self, partial(self.handle_remote_clone_confirmation, cdata), window=self,
title=_('Allow cloning of window?'),
) )
elif ac in ('yes', 'y', 'true'): elif ac in ('yes', 'y', 'true'):
self.handle_remote_clone_confirmation(cdata, True) self.handle_remote_clone_confirmation(cdata, True)
@@ -1475,14 +1476,15 @@ class Window:
get_boss().choose( get_boss().choose(
msg, partial(self.handle_dangerous_paste_confirmation, btext, sanitized), msg, partial(self.handle_dangerous_paste_confirmation, btext, sanitized),
's;green:Sanitize and paste', 'p;red:Paste anyway', 'c;yellow:Cancel', 's;green:Sanitize and paste', 'p;red:Paste anyway', 'c;yellow:Cancel',
window=self, default='s', window=self, default='s', title=_('Allow paste?'),
) )
return return
if 'confirm-if-large' in opts.paste_actions: if 'confirm-if-large' in opts.paste_actions:
msg = '' msg = ''
if len(btext) > 16 * 1024: if len(btext) > 16 * 1024:
msg = _('Pasting very large amounts of text ({} bytes) can be slow.').format(len(btext)) msg = _('Pasting very large amounts of text ({} bytes) can be slow.').format(len(btext))
get_boss().confirm(msg + _(' Are you sure?'), partial(self.handle_large_paste_confirmation, btext), window=self) get_boss().confirm(msg + _(' Are you sure?'), partial(self.handle_large_paste_confirmation, btext), window=self, title=_(
'Allow large paste?'))
return return
self.paste_text(btext) self.paste_text(btext)