Allow copying hyperlink URL to clipboard

This commit is contained in:
Kovid Goyal 2020-09-15 13:23:31 +05:30
parent 437efe5473
commit d60020f5ac
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 10 additions and 5 deletions

View File

@ -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}

View File

@ -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