From 40935ad6dc4ed4696c2f9f41b4ee6ef6a21f8910 Mon Sep 17 00:00:00 2001 From: icychkn Date: Mon, 19 Jun 2023 00:20:21 -0400 Subject: [PATCH] Added a check before the call to stty that ensures the stdin is a terminal, and applies the fallback values if not. --- filetags/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/filetags/__init__.py b/filetags/__init__.py index ffa5476..f1f51e8 100755 --- a/filetags/__init__.py +++ b/filetags/__init__.py @@ -81,10 +81,14 @@ if platform.system() == 'Windows': TTY_HEIGHT, TTY_WIDTH = 80, 80 # fall-back values IS_WINDOWS = True else: - try: - TTY_HEIGHT, TTY_WIDTH = [int(x) for x in os.popen('stty size', 'r').read().split()] - except ValueError: - TTY_HEIGHT, TTY_WIDTH = 80, 80 # fall-back values + # check to avoid unrecoverable stty error when stdin is not a terminal. + if sys.stdin.isatty(): + try: + TTY_HEIGHT, TTY_WIDTH = [int(x) for x in os.popen('stty size', 'r').read().split()] + except ValueError: + TTY_HEIGHT, TTY_WIDTH = 80, 80 # fall-back values + else: + TTY_HEIGHT, TTY_WIDTH = 80, 80 max_file_length = 0 # will be set after iterating over source files182