From 9a119255fe4741dffe0c56624987ce956ba58607 Mon Sep 17 00:00:00 2001 From: pagedown Date: Sat, 22 Jan 2022 03:11:39 +0800 Subject: [PATCH] ask kitten: Use the default value as input text Prefill the current value when changing the tab title. --- kittens/ask/main.py | 10 +++++++++- kitty/boss.py | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/kittens/ask/main.py b/kittens/ask/main.py index ed8f16ea0..a427a0c30 100644 --- a/kittens/ask/main.py +++ b/kittens/ask/main.py @@ -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} diff --git a/kitty/boss.py b/kitty/boss.py index 04a736cbd..c03feba1d 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -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: