Commit 43239ecd authored by Dylan's avatar Dylan

Fallback to ascii mode instead of hanging if the terminal emulator doesn't…

Fallback to ascii mode instead of hanging if the terminal emulator doesn't support xterm escape sequences
parent 6bb05edf
...@@ -262,8 +262,8 @@ crop_offset="center" ...@@ -262,8 +262,8 @@ crop_offset="center"
# Image size # Image size
# The image is half the terminal width by default. # The image is half the terminal width by default.
# --size half, px # --size auto, px
image_size="half" image_size="auto"
# Right gap between image and text # Right gap between image and text
# --gap num # --gap num
......
...@@ -280,8 +280,8 @@ crop_offset="center" ...@@ -280,8 +280,8 @@ crop_offset="center"
# Image size # Image size
# The image is half the terminal width by default. # The image is half the terminal width by default.
# --size half, px # --size auto, px
image_size="half" image_size="auto"
# Right gap between image and text # Right gap between image and text
# --gap num # --gap num
...@@ -1851,24 +1851,11 @@ getimage () { ...@@ -1851,24 +1851,11 @@ getimage () {
;; ;;
esac esac
# If $img isn't a file, fallback to ascii mode.
if [ ! -f "$img" ]; then
# Fallback to ascii mode
image="ascii"
getascii
return
fi
# Get terminal lines and columns
columns=$(tput cols)
lines=$(tput lines)
# Get terminal width and height # Get terminal width and height
printf "%b%s" '\033[14t' printf "%b%s" '\033[14t'
index=0 index=0
while IFS= read -s -r -n 1 char; do while IFS= read -s -r -n 1 -t 0.25 char; do
case "$index" in case "$index" in
"0") [ "$char" == ";" ] && index=$((index + 1)) ;; "0") [ "$char" == ";" ] && index=$((index + 1)) ;;
"1") [ "$char" == ";" ] && index=$((index + 1)) || term_height="${term_height}${char}" ;; "1") [ "$char" == ";" ] && index=$((index + 1)) || term_height="${term_height}${char}" ;;
...@@ -1876,12 +1863,26 @@ getimage () { ...@@ -1876,12 +1863,26 @@ getimage () {
esac esac
done done
# If $img isn't a file or the terminal doesn't support xterm escape sequences,
# fallback to ascii mode.
if [ ! -f "$img" ] || [ -z "$term_height" ]; then
# Fallback to ascii mode
image="ascii"
getascii
return
fi
# Get terminal lines and columns
columns=$(tput cols)
lines=$(tput lines)
# Calculate font size # Calculate font size
font_width=$((term_width / columns)) font_width=$((term_width / columns))
font_height=$((term_height / lines)) font_height=$((term_height / lines))
# Image size is half of the terminal # Image size is half of the terminal
if [ "$image_size" == "half" ]; then if [ "$image_size" == "auto" ]; then
image_size=$((columns * font_width / 2)) image_size=$((columns * font_width / 2))
[ "$((term_height - term_height / 4))" -lt "$image_size" ] && \ [ "$((term_height - term_height / 4))" -lt "$image_size" ] && \
......
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