From f48074c5ce8ecfbaa0a8f172d281d8253cf060cf Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sun, 16 Oct 2022 12:10:15 -0700 Subject: [PATCH] Handle exception from os when attempting to determine console sizes. --- src/pyutils/text_utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pyutils/text_utils.py b/src/pyutils/text_utils.py index f80073c..66f6f22 100644 --- a/src/pyutils/text_utils.py +++ b/src/pyutils/text_utils.py @@ -54,6 +54,15 @@ def get_console_rows_columns() -> RowsColumns: rows: Union[Optional[str], int] = os.environ.get('LINES', None) cols: Union[Optional[str], int] = os.environ.get('COLUMNS', None) + if not rows or not cols: + try: + size = os.get_terminal_size() + rows = size.lines + cols = size.columns + except Exception: + rows = None + cols = None + if not rows or not cols: logger.debug('Rows: %s, cols: %s, trying stty.', rows, cols) try: @@ -65,11 +74,6 @@ def get_console_rows_columns() -> RowsColumns: rows = None cols = None - if not rows or not cols: - size = os.get_terminal_size() - rows = size.lines - cols = size.columns - if not rows or not cols: raise Exception('Can\'t determine console size?!') return RowsColumns(int(rows), int(cols)) -- 2.45.2