Add a new mappable action open_url

This commit is contained in:
pagedown 2022-04-23 13:17:28 +08:00
parent 37cdaea9ed
commit a5bd1dcb08
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB
3 changed files with 16 additions and 0 deletions

View File

@ -51,6 +51,7 @@ Detailed list of changes
- Fix tab selection when closing a new tab not correct in some scenarios (:iss:`4987`)
- A new action :ac:`open_url` to open the specified URL (:pull:`5004`)
0.25.0 [2022-04-11]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -1513,6 +1513,7 @@ class Boss:
if tab:
tab.set_active_window(window_id)
@ac('misc', 'Open the specified URL')
def open_url(self, url: str, program: Optional[Union[str, List[str]]] = None, cwd: Optional[str] = None) -> None:
if not url:
return

View File

@ -91,6 +91,20 @@ def kitten_parse(func: str, rest: str) -> FuncArgsType:
return func, [args[0]] + (to_cmdline(args[1]) if len(args) > 1 else [])
@func_with_args('open_url')
def open_url_parse(func: str, rest: str) -> FuncArgsType:
from urllib.parse import urlparse
url = ''
try:
url = python_string(rest)
tokens = urlparse(url)
if not all((tokens.scheme, tokens.netloc,)):
raise ValueError('Invalid URL')
except Exception:
log_error('Ignoring invalid URL string: ' + rest)
return func, (url,)
@func_with_args('goto_tab')
def goto_tab_parse(func: str, rest: str) -> FuncArgsType:
args = (max(0, int(rest)), )