From ed76c4a4daf7ca92f833a38afa7aa6fb7dfa9001 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Mon, 25 Sep 2017 13:17:26 -0400 Subject: [PATCH] pipes Signed-off-by: Kenneth Reitz --- click_tools/pipes.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 click_tools/pipes.py diff --git a/click_tools/pipes.py b/click_tools/pipes.py new file mode 100644 index 0000000..fb32881 --- /dev/null +++ b/click_tools/pipes.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- + +import sys +import os + + +def piped_in(): + """Returns piped input via stdin, else None.""" + with sys.stdin as stdin: + # TTY is only way to detect if stdin contains data + if not stdin.isatty(): + return stdin.read() + else: + return None + + +def is_interactive(): + """Returns if the current session is interactive or not.""" + return bool(os.isatty(sys.stdout.fileno()))