mirror of
https://github.com/eth-p/bat-extras.git
synced 2024-11-07 16:24:06 +01:00
lib: Fix term_width to handle cases where stty size returns '0 0'
This commit is contained in:
parent
c98e21df04
commit
63101805be
12
lib/term.sh
12
lib/term.sh
@ -12,12 +12,12 @@
|
|||||||
# The terminal width, or 80 if there's no TTY.
|
# The terminal width, or 80 if there's no TTY.
|
||||||
#
|
#
|
||||||
term_width() {
|
term_width() {
|
||||||
if ! [[ -t 0 ]]; then
|
|
||||||
echo "80"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# shellcheck disable=SC2155
|
# shellcheck disable=SC2155
|
||||||
{ stty size 2>/dev/null || echo "22 80"; } | cut -d' ' -f2
|
local width="$({ stty size 2>/dev/null || echo "22 80"; } | cut -d ' ' -f2)"
|
||||||
|
if [[ "$width" -ne 0 ]]; then
|
||||||
|
echo "$width"
|
||||||
|
else
|
||||||
|
echo "80"
|
||||||
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user