From e36d41b46f368352c314e8460a9db3a53f81780c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 18 Sep 2020 11:48:31 +0530 Subject: [PATCH] Add a --hold option to icat Keeps it alive after display images --- kittens/icat/main.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/kittens/icat/main.py b/kittens/icat/main.py index e1c6be97a..45d3d60da 100755 --- a/kittens/icat/main.py +++ b/kittens/icat/main.py @@ -30,7 +30,7 @@ from ..tui.images import ( ConvertFailed, GraphicsCommand, NoImageMagick, OpenFailed, convert, fsenc, identify ) -from ..tui.operations import clear_images_on_screen +from ..tui.operations import clear_images_on_screen, raw_mode OPTIONS = '''\ --align @@ -110,6 +110,11 @@ default=0 Z-index of the image. When negative, text will be displayed on top of the image. Use a double minus for values under the threshold for drawing images under cell background colors. For example, --1 evaluates as -1,073,741,825. + + +--hold +type=bool-set +Wait for keypress before exiting after displaying the images. ''' @@ -473,11 +478,14 @@ def main(args: List[str] = sys.argv) -> None: errors.append(e) if parsed_opts.place: sys.stdout.buffer.write(b'\0338') # restore cursor - if not errors: - return - for err in errors: - print(err, file=sys.stderr) - raise SystemExit(1) + if errors: + for err in errors: + print(err, file=sys.stderr) + if cli_opts.hold: + with open(os.ctermid()) as tty: + with raw_mode(tty.fileno()): + tty.buffer.read(1) + raise SystemExit(1 if errors else 0) if __name__ == '__main__':