ask kitten: Use the default value as input text

Prefill the current value when changing the tab title.
This commit is contained in:
pagedown 2022-01-22 03:11:39 +08:00
parent 7ce11050cd
commit 9a119255fe
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB
2 changed files with 12 additions and 2 deletions

View File

@ -298,7 +298,15 @@ def main(args: List[str]) -> Response:
prompt = '> '
with suppress(KeyboardInterrupt, EOFError):
response = input(prompt)
if cli_opts.default:
def prefill_text():
readline.insert_text(cli_opts.default)
readline.redisplay()
readline.set_pre_input_hook(prefill_text)
response = input(prompt)
readline.set_pre_input_hook()
else:
response = input(prompt)
return {'items': items, 'response': response}

View File

@ -1418,7 +1418,9 @@ class Boss:
def set_tab_title(self) -> None:
tab = self.active_tab
if tab:
args = ['--name=tab-title', '--message', _('Enter the new title for this tab below.'), 'do_set_tab_title', str(tab.id)]
args = [
'--name=tab-title', '--message', _('Enter the new title for this tab below.'),
'--default', tab.name or tab.title, 'do_set_tab_title', str(tab.id)]
self._run_kitten('ask', args)
def do_set_tab_title(self, title: str, tab_id: int) -> None: