Fix STDIN pipe detection logic

This commit is contained in:
Kristóf Tóth 2022-02-10 01:46:35 +01:00
parent 5e4ac9681b
commit 67772abe6d
1 changed files with 1 additions and 6 deletions

View File

@ -1,6 +1,5 @@
from sys import argv, stdin from sys import argv, stdin
from sys import exit as sysexit from sys import exit as sysexit
from select import select
from hashlib import blake2b from hashlib import blake2b
from io import BytesIO from io import BytesIO
@ -24,15 +23,11 @@ def get_input_stream():
io = None io = None
if len(argv) == 2: if len(argv) == 2:
io = BytesIO(argv[1].encode()) io = BytesIO(argv[1].encode())
elif stdin_has_data(): elif not stdin.isatty():
io = stdin.buffer io = stdin.buffer
return io return io
def stdin_has_data():
return bool(select([stdin], [], [], 0.0)[0])
def print_usage_and_exit(): def print_usage_and_exit():
print('Usage: identicon [TEXT]') print('Usage: identicon [TEXT]')
print('Print OpenSSH style randomart identicon for arbitrary data.\n') print('Print OpenSSH style randomart identicon for arbitrary data.\n')