Commit 194c7b50 authored by Dylan Araps's avatar Dylan Araps

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

parent 60318bc1
...@@ -1964,67 +1964,65 @@ getimage() { ...@@ -1964,67 +1964,65 @@ getimage() {
;; ;;
esac esac
# Get terminal width and height if [ -n "$TMUX" ]; then
if type -p xdotool >/dev/null 2>&1 && \ printf "%b%s" "\033Ptmux;\033\033[14t\033\033[c\033\\"
[ "$image_backend" != "iterm2" ]; then read_flags="-d c"
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 " "}')" elif [ "$image_backend" == "tycat" ]; then
term_width="${term_size/ *}" printf "%b%s" "\033}qs\000"
term_height="${term_size/${term_width}}"
else else
if [ -n "$TMUX" ]; then printf "%b%s" "\033[14t\033[c"
printf "%b%s" "\033Ptmux;\033\033[14t\033\033[c\033\\" read_flags="-d c"
read_flags="-d c" fi
elif [ "$image_backend" == "tycat" ]; then # The escape code above prints the output AFTER the prompt so this
printf "%b%s" "\033}qs\000" builtin read -s -t 1 ${read_flags} -r term_size
else # Split the string
printf "%b%s" "\033[14t\033[c" if [ "$image_backend" == "tycat" ]; then
read_flags="-d c" term_size=(${term_size//;/ })
fi term_width="$((term_size[2] * term_size[0]))"
term_height="$((term_size[3] * term_size[1]))"
# The escape code above prints the output AFTER the prompt so this else
builtin read -s -t 1 ${read_flags} -r term_size 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
# Split the string # Get terminal width and height if \033[14t is unsupported.
if [ "$image_backend" == "tycat" ]; then if [ "${#term_size}" -le 5 ] && [ "$image_backend" != "tycat" ]; then
term_size=(${term_size//;/ }) if type -p xdotool >/dev/null 2>&1 && \
term_width="$((term_size[2] * term_size[0]))" [ "$image_backend" != "iterm2" ]; then
term_height="$((term_size[3] * term_size[1]))"
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
else term_size="$(xwininfo -id "$current_window" | awk -F ': ' '/Width|Height/ {printf $2 " "}')"
term_size="${term_size//'['}" term_width="${term_size/ *}"
term_size="${term_size/';'}" term_height="${term_size/${term_width}}"
term_size="${term_size/$'\E4'}"
term_size="${term_size/t*}"
term_height="${term_size/';'*}"
term_width="${term_size/*';'}"
fi fi
[ "${#term_size}" -le 5 ] && no_esc="1"
fi fi
# If $img isn't a file or the terminal doesn't support xterm escape sequences, # If $img isn't a file fallback to ascii mode.
# fallback to ascii mode. if [ ! -f "$img" ] || [ "$term_width" -le 10 ]; then
if [ ! -f "$img" ] || [ "$term_width" -le 10 ] || ([ "$no_esc" == 1 ] && [ "$image_backend" != "tycat" ]); then
image="ascii" image="ascii"
getascii getascii
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment