Allow copying hyperlink URL to clipboard
This commit is contained in:
parent
437efe5473
commit
d60020f5ac
@ -122,7 +122,7 @@ def choice(cli_opts: AskCLIOptions, items: List[str]) -> Response:
|
|||||||
letter = letter.lower()
|
letter = letter.lower()
|
||||||
idx = text.lower().index(letter)
|
idx = text.lower().index(letter)
|
||||||
allowed += 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()
|
print()
|
||||||
response = get_key_press(allowed, '')
|
response = get_key_press(allowed, '')
|
||||||
return {'items': items, 'response': response}
|
return {'items': items, 'response': response}
|
||||||
|
|||||||
@ -513,9 +513,11 @@ class Window:
|
|||||||
return
|
return
|
||||||
if self.opts.allow_hyperlinks & 0b10:
|
if self.opts.allow_hyperlinks & 0b10:
|
||||||
from kittens.tui.operations import styled
|
from kittens.tui.operations import styled
|
||||||
get_boss()._run_kitten('ask', ['--type=yesno', '--message', _(
|
get_boss()._run_kitten('ask', ['--type=choices', '--message', _(
|
||||||
'Do you want to open the following URL:\n') +
|
'What would you like to do with this URL:\n') +
|
||||||
styled(unquote(url), fg='yellow')],
|
styled(unquote(url), fg='yellow'),
|
||||||
|
'--choice=o:Open', '--choice=c:Copy to clipboard', '--choice=n;red:Nothing'
|
||||||
|
],
|
||||||
window=self,
|
window=self,
|
||||||
custom_callback=partial(self.hyperlink_open_confirmed, url)
|
custom_callback=partial(self.hyperlink_open_confirmed, url)
|
||||||
)
|
)
|
||||||
@ -523,8 +525,11 @@ class Window:
|
|||||||
get_boss().open_url(url)
|
get_boss().open_url(url)
|
||||||
|
|
||||||
def hyperlink_open_confirmed(self, url: str, data: Dict[str, Any], *a: Any) -> None:
|
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)
|
get_boss().open_url(url)
|
||||||
|
elif q == 'c':
|
||||||
|
set_clipboard_string(url)
|
||||||
|
|
||||||
def handle_remote_file(self, netloc: str, remote_path: str) -> None:
|
def handle_remote_file(self, netloc: str, remote_path: str) -> None:
|
||||||
from kittens.ssh.main import get_connection_data
|
from kittens.ssh.main import get_connection_data
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user