From fa01e0b76f31e556570be4490d6f3a438e124f1b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 16 Jan 2019 16:35:53 +0530 Subject: [PATCH] icat kitten: Add a --stdin option to control if image data is read from stdin See #1308 --- docs/changelog.rst | 3 +++ kittens/icat/main.py | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index a0403687c..d78ba1051 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,9 @@ Changelog 0.13.3 [future] ------------------------------ +- icat kitten: Add a ``--stdin`` option to control if image data is read from + stdin (:iss:`1308`) + - hints kitten: Start hints numbering at one instead of zero by default. Added an option ``--hints-offset`` to control it. (:iss:`1289`) diff --git a/kittens/icat/main.py b/kittens/icat/main.py index 9bf01d667..6946b6e0f 100755 --- a/kittens/icat/main.py +++ b/kittens/icat/main.py @@ -81,6 +81,14 @@ type=bool-set Print out the window size as :italic:`widthxheight` (in pixels) and quit. This is a convenience method to query the window size if using kitty icat from a scripting language that cannot make termios calls. + + +--stdin +type=choices +choices=detect,yes,no +default=detect +Read image data from stdin. The default is to do it automatically, when STDIN is not a terminal, +but you can turn it off or on explicitly, if needed. ''' @@ -269,9 +277,10 @@ def main(args=sys.argv): if not sys.stdout.isatty(): sys.stdout = open(os.ctermid(), 'w') stdin_data = None - if not sys.stdin.isatty(): + if args.stdin == 'yes' or (not sys.stdin.isatty() and args.stdin == 'detect'): stdin_data = sys.stdin.buffer.read() - items.insert(0, stdin_data) + if stdin_data: + items.insert(0, stdin_data) sys.stdin.close() sys.stdin = open(os.ctermid(), 'r') @@ -307,7 +316,7 @@ def main(args=sys.argv): raise SystemExit('You must specify at least one file to cat') if args.place: if len(items) > 1 or (isinstance(items[0], str) and os.path.isdir(items[0])): - raise SystemExit('The --place option can only be used with a single image') + raise SystemExit(f'The --place option can only be used with a single image, not {items}') sys.stdout.buffer.write(b'\0337') # save cursor for item in items: is_tempfile = False