1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 06:39:02 -08:00

detect size with stty size instead of tput

This commit is contained in:
Connor Olding 2021-10-07 13:12:25 -07:00
parent 38cd399bcf
commit f0fedca16f

20
sh/glug
View file

@ -19,11 +19,21 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
done
cd "$_here"
if [ -z "$ZSH_VERSION" ]; then
# TODO: is `stty size` more portable?
COLUMNS="${COLUMNS:-$(tput cols)}"
LINES="${LINES:-$(tput lines)}"
fi
detect_size() {
# globals: $COLUMNS, $LINES
_size="$(stty size)"
COLUMNS="${_size#* }"
LINES="${_size%% *}"
if [ "$COLUMNS" -gt 0 ] 2>/dev/null && [ "$LINES" -gt 0 ] 2>/dev/null; then
: # pass
else
printf '%s: failed to determine terminal size\n' glug >&2
return 2
fi
unset _size
}
[ -n "$ZSH_VERSION" ] || detect_size
if [ -n "$ZSH_VERSION" ] || [ -n "$BASH_VERSION" ]; then
esc=$'\e'