import sys
from collections import defaultdict
from dataclasses import dataclass
-from typing import Dict, Generator, List, Literal, Optional, Tuple
+from typing import Dict, Generator, List, Literal, Optional, Tuple, Union
from pyutils import string_utils
from pyutils.ansi import fg, reset
"""
from pyutils.exec_utils import cmd
- rows: Optional[str] = os.environ.get('LINES', None)
- cols: Optional[str] = os.environ.get('COLUMNS', None)
+ 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:
- logger.debug('Rows: %s, cols: %s, trying stty.', rows, cols)
try:
- rows, cols = cmd(
- "stty size",
- timeout_seconds=1.0,
- ).split()
+ size = os.get_terminal_size()
+ rows = size.lines
+ cols = size.columns
except Exception:
rows = None
cols = None
- if rows is None:
- logger.debug('Rows: %s, cols: %s, tput rows.', rows, cols)
+ if not rows or not cols:
+ logger.debug('Rows: %s, cols: %s, trying stty.', rows, cols)
try:
- rows = cmd(
- "tput rows",
+ rows, cols = cmd(
+ "stty size",
timeout_seconds=1.0,
- )
+ ).split()
except Exception:
rows = None
-
- if cols is None:
- logger.debug('Rows: %s, cols: %s, tput cols.', rows, cols)
- try:
- cols = cmd(
- "tput cols",
- timeout_seconds=1.0,
- )
- except Exception:
cols = None
if not rows or not cols: