mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 03:01:57 +02:00
icat: Fix --hold not working with critical errors
This commit is contained in:
@@ -550,16 +550,26 @@ def main(args: List[str] = sys.argv) -> None:
|
|||||||
raise SystemExit(f'The --place option can only be used with a single image, not {items}')
|
raise SystemExit(f'The --place option can only be used with a single image, not {items}')
|
||||||
sys.stdout.buffer.write(b'\0337') # save cursor
|
sys.stdout.buffer.write(b'\0337') # save cursor
|
||||||
url_pat = re.compile(r'(?:https?|ftp)://', flags=re.I)
|
url_pat = re.compile(r'(?:https?|ftp)://', flags=re.I)
|
||||||
|
|
||||||
|
def hold_if_needed(exit_code_or_msg: Union[int, str]) -> None:
|
||||||
|
if cli_opts.hold:
|
||||||
|
if isinstance(exit_code_or_msg, str):
|
||||||
|
print(exit_code_or_msg, file=sys.stderr, flush=True)
|
||||||
|
exit_code_or_msg = 1
|
||||||
|
with open(os.ctermid()) as tty, raw_mode(tty.fileno()):
|
||||||
|
tty.buffer.read(1)
|
||||||
|
raise SystemExit(exit_code_or_msg)
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
try:
|
try:
|
||||||
process_single_item(item, cli_opts, parsed_opts, url_pat)
|
process_single_item(item, cli_opts, parsed_opts, url_pat)
|
||||||
except NoImageMagick as e:
|
except NoImageMagick as e:
|
||||||
raise SystemExit(str(e))
|
hold_if_needed(str(e))
|
||||||
except OutdatedImageMagick as e:
|
except OutdatedImageMagick as e:
|
||||||
print(e.detailed_error, file=sys.stderr)
|
print(e.detailed_error, file=sys.stderr)
|
||||||
raise SystemExit(str(e))
|
hold_if_needed(str(e))
|
||||||
except ConvertFailed as e:
|
except ConvertFailed as e:
|
||||||
raise SystemExit(str(e))
|
hold_if_needed(str(e))
|
||||||
except OpenFailed as e:
|
except OpenFailed as e:
|
||||||
errors.append(e)
|
errors.append(e)
|
||||||
if parsed_opts.place:
|
if parsed_opts.place:
|
||||||
@@ -567,11 +577,8 @@ def main(args: List[str] = sys.argv) -> None:
|
|||||||
if errors:
|
if errors:
|
||||||
for err in errors:
|
for err in errors:
|
||||||
print(err, file=sys.stderr)
|
print(err, file=sys.stderr)
|
||||||
if cli_opts.hold:
|
hold_if_needed(1 if errors else 0)
|
||||||
with open(os.ctermid()) as tty:
|
raise SystemExit()
|
||||||
with raw_mode(tty.fileno()):
|
|
||||||
tty.buffer.read(1)
|
|
||||||
raise SystemExit(1 if errors else 0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user