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
3 changed files with 16 additions and 0 deletions

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)), )