# tty size
# && true is to force spawning a shell and not just exec'ing
cols=$(stty size </dev/tty 2>/dev/null | awk '{ print $2 }' && true)
if [ "${cols}" -le 0 ]; then
  cols="${COLUMNS:-80}"
fi
COLUMNS="${COLUMNS:-${cols}}"

# cols="$(stty size </dev/tty | awk '{ print $2 }')"
# lines="$(stty size </dev/tty | awk '{ print $1 }')"

# query the terminal to establish a default number of columns to use for
# displaying messages to the user.
# $COLUMNS can react to SIGWINCH while the script is running,
# and this cannot, only being calculated once.
DEFCOLUMNS=$(stty size 2>/dev/null | awk '{ print $2 }') || true
if ! expr "${DEFCOLUMNS}" : "[[:digit:]]\+$" >/dev/null 2>&1; then
  DEFCOLUMNS=80
fi

# LINES=$(stty size </dev/tty) && LINES=${LINES% *}
# printf '%s' "${LINES:-24}"
# COLUMNS=$(stty size </dev/tty) && COLUMNS=${COLUMNS#* }
# printf '%s' "${COLUMNS:-80}"
