From d60020f5ac8caac4b491a518596134b8a4822639 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 15 Sep 2020 13:23:31 +0530 Subject: [PATCH] Allow copying hyperlink URL to clipboard --- kittens/ask/main.py | 2 +- kitty/window.py | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/kittens/ask/main.py b/kittens/ask/main.py index c7b96356b..792663438 100644 --- a/kittens/ask/main.py +++ b/kittens/ask/main.py @@ -122,7 +122,7 @@ def choice(cli_opts: AskCLIOptions, items: List[str]) -> Response: letter = letter.lower() idx = text.lower().index(letter) allowed += letter - print(text[:idx], styled(text[idx], fg=color), text[idx:], sep='', end=' ') + print(text[:idx], styled(text[idx], fg=color), text[idx + 1:], sep='', end=' ') print() response = get_key_press(allowed, '') return {'items': items, 'response': response} diff --git a/kitty/window.py b/kitty/window.py index 8d8863078..d553a79dd 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -513,9 +513,11 @@ class Window: return if self.opts.allow_hyperlinks & 0b10: from kittens.tui.operations import styled - get_boss()._run_kitten('ask', ['--type=yesno', '--message', _( - 'Do you want to open the following URL:\n') + - styled(unquote(url), fg='yellow')], + get_boss()._run_kitten('ask', ['--type=choices', '--message', _( + 'What would you like to do with this URL:\n') + + styled(unquote(url), fg='yellow'), + '--choice=o:Open', '--choice=c:Copy to clipboard', '--choice=n;red:Nothing' + ], window=self, custom_callback=partial(self.hyperlink_open_confirmed, url) ) @@ -523,8 +525,11 @@ class Window: get_boss().open_url(url) def hyperlink_open_confirmed(self, url: str, data: Dict[str, Any], *a: Any) -> None: - if data['response'] == 'y': + q = data['response'] + if q == 'o': get_boss().open_url(url) + elif q == 'c': + set_clipboard_string(url) def handle_remote_file(self, netloc: str, remote_path: str) -> None: from kittens.ssh.main import get_connection_data