Images: Use \033[14t before falling back to external programs

This commit is contained in:
Dylan Araps 2016-10-31 14:57:04 +11:00
parent 60318bc194
commit 194c7b500d
1 changed files with 54 additions and 56 deletions

View File

@ -1964,31 +1964,6 @@ getimage() {
;; ;;
esac esac
# Get terminal width and height
if type -p xdotool >/dev/null 2>&1 && \
[ "$image_backend" != "iterm2" ]; then
current_window="$(xdotool getactivewindow)"
eval "$(xdotool getwindowgeometry --shell "$current_window")"
term_height="$HEIGHT"
term_width="$WIDTH"
elif type -p xwininfo >/dev/null 2>&1 && \
type -p xdpyinfo >/dev/null 2>&1 || \
type -p xprop >/dev/null 2>&1 && \
[ "$image_backend" != "iterm2" ]; then
if type -p xdpyinfo >/dev/null 2>&1; then
current_window="$(xdpyinfo | grep focus | grep -E -o 0x[0-9a-f]+)"
elif type -p xprop >/dev/null 2>&1; then
current_window="$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')"
fi
term_size="$(xwininfo -id "$current_window" | awk -F ': ' '/Width|Height/ {printf $2 " "}')"
term_width="${term_size/ *}"
term_height="${term_size/${term_width}}"
else
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\\"
read_flags="-d c" read_flags="-d c"
@ -2019,12 +1994,35 @@ getimage() {
term_width="${term_size/*';'}" term_width="${term_size/*';'}"
fi fi
[ "${#term_size}" -le 5 ] && no_esc="1" # Get terminal width and height if \033[14t is unsupported.
if [ "${#term_size}" -le 5 ] && [ "$image_backend" != "tycat" ]; then
if type -p xdotool >/dev/null 2>&1 && \
[ "$image_backend" != "iterm2" ]; then
current_window="$(xdotool getactivewindow)"
eval "$(xdotool getwindowgeometry --shell "$current_window")"
term_height="$HEIGHT"
term_width="$WIDTH"
elif type -p xwininfo >/dev/null 2>&1 && \
type -p xdpyinfo >/dev/null 2>&1 || \
type -p xprop >/dev/null 2>&1 && \
[ "$image_backend" != "iterm2" ]; then
if type -p xdpyinfo >/dev/null 2>&1; then
current_window="$(xdpyinfo | grep focus | grep -E -o 0x[0-9a-f]+)"
elif type -p xprop >/dev/null 2>&1; then
current_window="$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')"
fi fi
# If $img isn't a file or the terminal doesn't support xterm escape sequences, term_size="$(xwininfo -id "$current_window" | awk -F ': ' '/Width|Height/ {printf $2 " "}')"
# fallback to ascii mode. term_width="${term_size/ *}"
if [ ! -f "$img" ] || [ "$term_width" -le 10 ] || ([ "$no_esc" == 1 ] && [ "$image_backend" != "tycat" ]); then term_height="${term_size/${term_width}}"
fi
fi
# If $img isn't a file fallback to ascii mode.
if [ ! -f "$img" ] || [ "$term_width" -le 10 ]; then
image="ascii" image="ascii"
getascii getascii