Report errors correctly when launching multiple URLs

This commit is contained in:
Kovid Goyal 2022-02-07 14:07:17 +05:30
parent ba97a728f2
commit 0fcfaa2a98
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2250,8 +2250,13 @@ class Boss:
from .launch import force_window_launch from .launch import force_window_launch
from .open_actions import actions_for_launch from .open_actions import actions_for_launch
actions: List[KeyAction] = [] actions: List[KeyAction] = []
failures = []
for url in urls: for url in urls:
actions.extend(actions_for_launch(url)) uactions = tuple(actions_for_launch(url))
if uactions:
actions.extend(uactions)
else:
failures.append(url)
tab = self.active_tab tab = self.active_tab
if tab is not None: if tab is not None:
w = tab.active_window w = tab.active_window
@ -2267,12 +2272,14 @@ class Boss:
if needs_window_replaced and tab is not None and w is not None: if needs_window_replaced and tab is not None and w is not None:
tab.remove_window(w) tab.remove_window(w)
if not actions: if failures:
with force_window_launch(needs_window_replaced): with force_window_launch(needs_window_replaced):
self.launch(kitty_exe(), '+runpy', f'print("The url:", {urls[0]!r}, "is of unknown type, cannot open it.");' from kittens.tui.operations import styled
'from kitty.utils import hold_till_enter; hold_till_enter(); raise SystemExit(1)') spec = '\n '.join(styled(u, fg='red') for u in failures)
self.launch('--hold', '--type=os-window', kitty_exe(), '+runpy', fr'print("Unknown URL type, cannot open:\n\n ", {spec!r});')
clear_initial_window() clear_initial_window()
else: needs_window_replaced = False
if actions:
with force_window_launch(needs_window_replaced): with force_window_launch(needs_window_replaced):
self.dispatch_action(actions.pop(0)) self.dispatch_action(actions.pop(0))
clear_initial_window() clear_initial_window()