Add terminology support

This commit is contained in:
Dylan Araps 2016-06-10 17:58:24 +10:00
parent 0527469643
commit 0825e282cd

View file

@ -2277,23 +2277,41 @@ getimage () {
stty -echo stty -echo
if [ -n "$TMUX" ]; then if [ -n "$TMUX" ]; then
printf "%b%s" "\033Ptmux;\033\033[14t\033\033[c\033\\" printf "%b%s" "\033Ptmux;\033\033[14t\033\033[c\033\\"
elif [ "$image_backend" == "tycat" ]; then
printf "%b%s" "\033}qs\000"
else else
printf "%b%s" "\033[14t\033[c" printf "%b%s" "\033[14t\033[c"
fi fi
# The escape code above prints the output AFTER the prompt so this # The escape 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 / terminology
read -t 1 -d c -s -r term_size if [ "$image_backend" == "tycat" ]; then
read -t 1 -s -r term_size
else
read -t 1 -d c -s -r term_size
fi
stty echo stty echo
# Split the string # Split the string
term_size=${term_size//'['} if [ "$image_backend" == "tycat" ]; then
term_size=${term_size/';'} lines=${term_size%%';'*}
term_size=${term_size/$'\E4'} columns=${term_size%';'*';'*}
term_size=${term_size/t*} columns=${columns#*';'}
term_height=${term_size/';'*} font_height=${term_size##*';'}
term_width=${term_size/*';'} font_weight=${term_size#*';'*';'}
font_weight=${font_weight%';'*}
term_height=$((font_height * columns))
term_width=$((font_weight * lines))
else
term_size=${term_size//'['}
term_size=${term_size/';'}
term_size=${term_size/$'\E4'}
term_size=${term_size/t*}
term_height=${term_size/';'*}
term_width=${term_size/*';'}
fi
# 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.
@ -3287,6 +3305,10 @@ if [ "$image" != "off" ]; then
# If iterm2 is detected use iterm2 backend. # If iterm2 is detected use iterm2 backend.
if [ -n "$ITERM_PROFILE" ]; then if [ -n "$ITERM_PROFILE" ]; then
image_backend="iterm2" image_backend="iterm2"
elif [ ! -z "$(tycat 2>/dev/null)" ]; then
image_backend="tycat"
else else
image_backend="w3m" image_backend="w3m"
fi fi
@ -3311,6 +3333,10 @@ if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then
"iterm2") "iterm2")
printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")" printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")"
;; ;;
"tycat")
tycat "$img"
;;
esac esac
fi fi