From: Scott Gasch Date: Sun, 16 Oct 2022 19:10:15 +0000 (-0700) Subject: Handle exception from os when attempting to determine console sizes. X-Git-Url: https://wannabe.guru.org/gitweb/?a=commitdiff_plain;h=f48074c5ce8ecfbaa0a8f172d281d8253cf060cf;p=pyutils.git Handle exception from os when attempting to determine console sizes. --- 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))