Reduce the amount of stuff we do in the image size while loop.

This commit is contained in:
Dylan 2016-02-21 14:37:17 +11:00
parent ba67112434
commit aa1272ffa9
1 changed files with 14 additions and 7 deletions

21
fetch
View File

@ -1794,6 +1794,10 @@ getimage () {
# Get terminal lines # Get terminal lines
lines=$(tput lines) lines=$(tput lines)
# If we're in a screen session, fallback to
# ascii mode.
[ -n "$STY" ] && image="ascii"
# Call function based on $image # Call function based on $image
case "$image" in case "$image" in
"wall") getwallpaper ;; "wall") getwallpaper ;;
@ -1811,23 +1815,26 @@ getimage () {
# The ascape code above prints the output AFTER the prompt so this # The ascape code above prints the output AFTER the prompt so this
# loop below reads it as input. wtf xterm # loop below reads it as input. wtf xterm
index=0
while IFS= read -s -r -n 1 -t 0.25 char; do while IFS= read -s -r -n 1 -t 0.25 char; do
case "$index" in [ "$char" == "t" ] && break
"0") [ "$char" == ";" ] && index=$((index + 1)) ;; term_size+=$char
"1") [ "$char" == ";" ] && index=$((index + 1)) || term_height="${term_height}${char}" ;;
"2") [ "$char" == "t" ] && break || term_width="${term_width}${char}"
esac
done done
# If $img isn't a file or the terminal doesn't support xterm escape sequences, # If $img isn't a file or the terminal doesn't support xterm escape sequences,
# fallback to ascii mode. # fallback to ascii mode.
if [ ! -f "$img" ] || [ -z "$term_height" ]; then if [ ! -f "$img" ] || [ -z "$term_size" ]; then
image="ascii" image="ascii"
getascii getascii
return return
fi fi
# Split the string
term_size=${term_size//'['}
term_size=${term_size/';'}
term_size=${term_size/$'\E4'}
term_height=${term_size/';'*}
term_width=${term_size/*';'}
# Get terminal columns # Get terminal columns
columns=$(tput cols) columns=$(tput cols)