From 40935ad6dc4ed4696c2f9f41b4ee6ef6a21f8910 Mon Sep 17 00:00:00 2001 From: icychkn Date: Mon, 19 Jun 2023 00:20:21 -0400 Subject: [PATCH 1/2] 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 From c50b0d8def2ae21a3ce07d2d63a8d765c6c6a777 Mon Sep 17 00:00:00 2001 From: icychkn Date: Mon, 19 Jun 2023 00:30:09 -0400 Subject: [PATCH 2/2] fixed misleading comment, error is not unrecoverable, nor does it halt the program. --- filetags/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/filetags/__init__.py b/filetags/__init__.py index f1f51e8..8193c41 100755 --- a/filetags/__init__.py +++ b/filetags/__init__.py @@ -81,7 +81,7 @@ if platform.system() == 'Windows': TTY_HEIGHT, TTY_WIDTH = 80, 80 # fall-back values IS_WINDOWS = True else: - # check to avoid unrecoverable stty error when stdin is not a terminal. + # check to avoid 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()]