From 0b3a5a7d4568aacc07096b0acfd992ab3f3e0c25 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 16 Dec 2017 10:33:16 +0530 Subject: [PATCH] icat: Add --clear to clear all display images --- kitty/icat.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/kitty/icat.py b/kitty/icat.py index 3cdf5003c..3f74077af 100755 --- a/kitty/icat.py +++ b/kitty/icat.py @@ -56,6 +56,11 @@ are in cells (i.e. cursor positions) with the origin |_ (0, 0)| at the top-left corner of the screen. +--clear +type=bool-set +Remove all images currently displayed on the screen. + + --transfer-mode type=choices choices=detect,file,stream @@ -101,10 +106,14 @@ def screen_size(refresh=False): return screen_size.ans -def write_gr_cmd(cmd, payload): +def write_gr_cmd(cmd, payload=None): cmd = ','.join('{}={}'.format(k, v) for k, v in cmd.items()) w = sys.stdout.buffer.write - w(b'\033_G'), w(cmd.encode('ascii')), w(b';'), w(payload), w(b'\033\\') + w(b'\033_G'), w(cmd.encode('ascii')) + if payload: + w(b';') + w(payload) + w(b'\033\\') sys.stdout.flush() @@ -336,14 +345,18 @@ def main(args=sys.argv): raise SystemExit(1) print('file' if detect_support.has_files else 'stream', end='', file=sys.stderr) return - if not items: - raise SystemExit('You must specify at least one file to cat') if args.transfer_mode == 'detect': if not detect_support(wait_for=args.detection_timeout): raise SystemExit('This terminal emulator does not support the graphics protocol, use a terminal emulator such as kitty that does support it') else: detect_support.has_files = args.transfer_mode == 'file' errors = [] + if args.clear: + write_gr_cmd({'a': 'd'}) + if not items: + return + if not items: + raise SystemExit('You must specify at least one file to cat') if args.place: if len(items) > 1 or os.path.isdir(items[0]): raise SystemExit('The --place option can only be used with a single image')