Images: Fix bugs

This commit is contained in:
Dylan Araps 2016-12-22 20:39:43 +11:00
parent 8318a9c30c
commit 4ca4e88697

View file

@ -1832,9 +1832,9 @@ get_image_backend() {
# If image source is ascii fallback to ascii. # If image source is ascii fallback to ascii.
if [[ "$image_source" == "ascii" ]]; then if [[ "$image_source" == "ascii" ]]; then
image_backend="ascii" to_ascii "Image: \$image_source set to 'ascii', falling back to ascii mode."
err "Image: \$image_source set to 'ascii', falling back to ascii mode. "
err "Image: Change \$image_source to another value to use image mode." err "Image: Change \$image_source to another value to use image mode."
return
fi fi
case "${image_backend:=image}" in case "${image_backend:=image}" in
@ -1861,8 +1861,9 @@ get_image_backend() {
get_term_size get_term_size
# Fallback to ascii mode if terminal size wasn't found. # Fallback to ascii mode if terminal size wasn't found.
if [[ -z "$term_width" ]] && ((term_width == 0)); then if [[ -z "$term_width" ]] || ((term_width == 0)); then
to_ascii "Image: Failed to find terminal window size" to_ascii "Image: Failed to find terminal window size"
err "Image: Check the 'Images in the terminal' wiki page for more info"
return return
fi fi
@ -1878,8 +1879,7 @@ get_image_backend() {
esac esac
# Set cursor position next to ascii art. # Set cursor position next to ascii art.
[[ "$image_backend" != "off" ]] && \ [[ "$image_backend" != "off" ]] && printf "%b" "\033[${lines:-0}A\033[9999999D"
printf "%b" "\033[$((${lines:-0} - ${prompt_loc:-0}))A\033[9999999D"
} }
get_ascii() { get_ascii() {
@ -2063,7 +2063,7 @@ get_term_size() {
# The escape codes above print the desired output as # The escape codes above print the desired output as
# user input so we have to use read to store the out # user input so we have to use read to store the out
# -put as a variable. # -put as a variable.
builtin read -s -t 1 "${read_flags[@]}" -r term_size IFS=";" read -s -t 1 "${read_flags[@]}" -r -a term_size
# Split the string into height/width. # Split the string into height/width.
if [[ "$image_program" == "tycat" ]]; then if [[ "$image_program" == "tycat" ]]; then
@ -2072,16 +2072,12 @@ get_term_size() {
term_height="$((term_size[3] * term_size[1]))" term_height="$((term_size[3] * term_size[1]))"
else else
term_size="${term_size//'['}" term_height="${term_size[1]}"
term_size="${term_size/';'}" term_width="${term_size[2]/t*}"
term_size="${term_size/$'\E4'}"
term_size="${term_size/t*}"
term_height="${term_size/';'*}"
term_width="${term_size/*';'}"
fi fi
# Get terminal width/height if \033[14t is unsupported. # Get terminal width/height if \033[14t is unsupported.
if (("${#term_size}" <= 5)) && [[ "$image_program" == "w3m" ]]; then if [[ -z "$term_width" && "$image_program" == "w3m" ]]; then
if type -p xdotool >/dev/null 2>&1; then if type -p xdotool >/dev/null 2>&1; then
current_window="$(xdotool getactivewindow)" current_window="$(xdotool getactivewindow)"
source <(xdotool getwindowgeometry --shell "$current_window") source <(xdotool getwindowgeometry --shell "$current_window")
@ -2103,15 +2099,15 @@ get_term_size() {
term_width="${term_size/ *}" term_width="${term_size/ *}"
term_height="${term_size/${term_width}}" term_height="${term_size/${term_width}}"
else else
term_width="0" term_width=0
fi fi
else else
term_width="0" term_width=0
fi fi
fi fi
# If the terminal size was found correctly. # If the terminal size was found correctly.
if [[ "$term_width" ]] && ((term_width > 0)); then if [[ "$term_width" ]] && ((term_width >= 1)); then
clear clear
zws=" " zws=" "
fi fi
@ -2258,7 +2254,14 @@ display_image() {
to_ascii() { to_ascii() {
# This function makes neofetch fallback to ascii mode. # This function makes neofetch fallback to ascii mode.
image_backend="ascii" image_backend="ascii"
# Print the ascii art.
get_ascii 2>/dev/null get_ascii 2>/dev/null
# Move cursor next to ascii art.
printf "%b" "\033[${lines:-0}A\033[9999999D"
# Log the error.
err "$1" err "$1"
} }
@ -2942,7 +2945,7 @@ old_options() {
[[ "$speed_type" == "bios" ]] && err "Config: speed_type='bios' is deprecated, use speed_type='bios_limit' instead." [[ "$speed_type" == "bios" ]] && err "Config: speed_type='bios' is deprecated, use speed_type='bios_limit' instead."
# Ascii_logo_size was removed in 2.1.0. # Ascii_logo_size was removed in 2.1.0.
[[ "$ascii_logo_size" ]] && err "Config: ascii_logo_size is deprecatedm use ascii_distro='{arch,crux,gentoo}_small' instead." [[ "$ascii_logo_size" ]] && err "Config: ascii_logo_size is deprecated, use ascii_distro='{arch,crux,gentoo}_small' instead."
} }
cache_uname() { cache_uname() {