Commit 89c43b1f authored by Dylan Araps's avatar Dylan Araps Committed by GitHub

Merge pull request #436 from dylanaraps/image

Images: Rewrite image functions
parents 232ac07f aba89c8a
...@@ -287,8 +287,8 @@ disk_display="off" ...@@ -287,8 +287,8 @@ disk_display="off"
# Image Source # Image Source
# --image wall, ascii, /path/to/img, /path/to/dir/, off # --image wallpaper, /path/to/img, /path/to/dir/, off
image="wall" image_source="wallpaper"
# Thumbnail directory # Thumbnail directory
thumbnail_dir="$HOME/.cache/thumbnails/neofetch" thumbnail_dir="$HOME/.cache/thumbnails/neofetch"
......
...@@ -1464,7 +1464,7 @@ get_term_font() { ...@@ -1464,7 +1464,7 @@ get_term_font() {
case "$term" in case "$term" in
"urxvt" | "urxvtd" | "xterm") "urxvt" | "urxvtd" | "xterm")
term_font="$(grep -i -F "${term/d}*font" <<< "$(xrdb -query)")" term_font="$(grep -i -F "${term/d}*font" < <(xrdb -query))"
term_font="${term_font/*font:}" term_font="${term_font/*font:}"
term_font="$(trim "$term_font")" term_font="$(trim "$term_font")"
...@@ -1791,69 +1791,81 @@ get_cols() { ...@@ -1791,69 +1791,81 @@ get_cols() {
# Add newlines to the string. # Add newlines to the string.
cols="${cols%%'nl'}" cols="${cols%%'nl'}"
cols="${cols//nl/\\n${padding}${zws}}" cols="${cols//nl/\\n\\033[${text_padding}C${zws}}"
fi fi
} }
# IMAGES # IMAGES
get_wallpaper() { get_image_backend() {
case "$os" in # This function determines which image backend to use
"Linux" | "BSD") # by checking for programs and etc.
if type -p feh >/dev/null && [[ -f "$HOME/.fehbg" ]]; then
img="$(awk -F\' '/feh/ {printf $2}' "$HOME/.fehbg")"
elif type -p nitrogen >/dev/null; then # Automatically find w3m-img
img="$(awk -F'=' '/file/ {printf $2;exit;}' "$XDG_CONFIG_HOME/nitrogen/bg-saved.cfg")" get_w3m_img_path
elif type -p gsettings >/dev/null; then # Fallback to ascii mode if imagemagick isn't installed.
# Get DE if user has disabled the function. type -p convert >/dev/null 2>&1 || image_backend="ascii"
[[ -z "$de" ]] && get_de
case "$de" in case "${image_backend:=image}" in
"MATE"*) img="$(gsettings get org.mate.background picture-filename)" ;; "image")
*) img="$(gsettings get org.gnome.desktop.background picture-uri)" ;; case "$image_source" in
esac "wall"*) get_wallpaper 2>/dev/null ;;
"off") image_backend="off"; return ;;
*)
if [[ -d "$image_source" ]]; then
files=("${image_source%/}"/*.{png,jpg,jpeg})
image="$(printf "%s" "${files[RANDOM % (${#files[@]} - 1)]}")"
else
image="$image_source"
fi
;;
esac
# Strip quotes etc from the path. # Fallback to ascii mode if image isn't a file.
img="${img/'file://'}" if [[ ! -f "$image" ]]; then
img="${img//\'}" to_ascii "Image: '$image' doesn't exist, falling back to ascii mode."
img="${img//\%20/ }" return
fi fi
;;
"Mac OS X") get_image_program
img="$(osascript -e 'tell application "System Events" to picture of current desktop')" get_term_size
;;
"Windows") # Fallback to ascii mode if terminal size wasn't found.
case "$distro" in if [[ -z "$term_width" ]] && ((term_width == 0)); then
"Windows XP") to_ascii "Image: Failed to find terminal window size"
img="/cygdrive/c/Documents and Settings/${USER}" return
img+="/Local Settings/Application Data/Microsoft" fi
img+="/Wallpaper1.bmp"
;;
"Windows"*) get_image_size
img="$APPDATA/Microsoft/Windows/Themes" make_thumbnail
img+="/TranscodedWallpaper.jpg"
;; # If the backend is still set to 'image' after
esac # make_thumbnail(), then display the image.
[[ "$image_backend" == "image" ]] && display_image
;; ;;
"ascii") get_ascii 2>/dev/null ;;
esac esac
}
# If img is an xml file don't use it. get_image_program() {
[[ "${img/*\./}" == "xml" ]] && img="" if [[ -n "$ITERM_PROFILE" ]]; then
image_program="iterm2"
elif [[ "$(tycat 2>/dev/null)" ]]; then
image_program="tycat"
# Error msg else
[[ -z "$img" ]] && err "Image: Wallpaper detection failed, falling back to ascii mode." image_program="w3m"
fi
} }
get_ascii() { get_ascii() {
if [[ ! -f "$ascii" || "$ascii" == "distro" ]]; then if [[ ! -f "$ascii" || "$ascii" == "distro" ]]; then
# Error message # Error message
[[ "$ascii" != "distro" ]] && \ [[ "$ascii" != "distro" ]] && [[ ! -f "$ascii" ]] && \
[[ ! -f "$ascii" ]] && err "Ascii: Ascii file not found, using distro ascii" err "Ascii: Ascii file not found, using distro ascii."
# Lowercase the distro name # Lowercase the distro name
if (("$version" <= 3)); then if (("$version" <= 3)); then
...@@ -1880,14 +1892,13 @@ get_ascii() { ...@@ -1880,14 +1892,13 @@ get_ascii() {
get_script_dir 2>/dev/null get_script_dir 2>/dev/null
# If the ascii file doesn't exist fallback to text mode. # If the ascii file doesn't exist fallback to text mode.
if [[ ! -f "$script_dir/ascii/distro/${ascii/ *}" ]]; then if [[ -f "$script_dir/ascii/distro/${ascii/ *}" ]]; then
padding="\033[0C" ascii="$script_dir/ascii/distro/${ascii/ *}"
image="off"
err "Ascii: Ascii file not found, falling back to text mode." else
to_off "Ascii: Ascii file not found, falling back to text mode."
return return
fi fi
ascii="$script_dir/ascii/distro/${ascii/ *}"
fi fi
fi fi
...@@ -1916,33 +1927,99 @@ get_ascii() { ...@@ -1916,33 +1927,99 @@ get_ascii() {
# Overwrite padding if ascii_length_force is set. # Overwrite padding if ascii_length_force is set.
[[ "$ascii_length_force" ]] && ascii_length="$ascii_length_force" [[ "$ascii_length_force" ]] && ascii_length="$ascii_length_force"
padding="\033[$((ascii_length + gap))C" text_padding="$((ascii_length + gap))"
printf "%b" "$print" printf "%b" "$print"
export LC_ALL=C export LC_ALL=C
} }
get_image() { get_w3m_img_path() {
# Fallback to ascii mode if imagemagick isn't installed. if [[ -x "$w3m_img_path" ]]; then
type -p convert >/dev/null 2>&1 || image="ascii" return
case "$image" in elif [[ -x "/usr/lib/w3m/w3mimgdisplay" ]]; then
"wall") get_wallpaper 2>/dev/null ;; w3m_img_path="/usr/lib/w3m/w3mimgdisplay"
"ascii") get_ascii; return ;;
*) elif [[ -x "/usr/libexec/w3m/w3mimgdisplay" ]]; then
if [[ -d "$image" ]]; then w3m_img_path="/usr/libexec/w3m/w3mimgdisplay"
files=("${image%/}"/*.{png,jpg,jpeg})
img="$(printf "%s" "${files[RANDOM % (${#files[@]} - 1)]}")" elif [[ -x "/usr/lib64/w3m/w3mimgdisplay" ]]; then
else w3m_img_path="/usr/lib64/w3m/w3mimgdisplay"
img="$image"
elif [[ -x "/usr/libexec64/w3m/w3mimgdisplay" ]]; then
w3m_img_path="/usr/libexec64/w3m/w3mimgdisplay"
else
image_backend="ascii"
err "Image: w3m-img wasn't found on your system, falling back to ascii mode."
fi
}
get_wallpaper() {
case "$os" in
"Linux" | "BSD")
if type -p feh >/dev/null && [[ -f "$HOME/.fehbg" ]]; then
image="$(awk -F\' '/feh/ {printf $2}' "$HOME/.fehbg")"
elif type -p nitrogen >/dev/null; then
image="$(awk -F'=' '/file/ {printf $2;exit;}' "$XDG_CONFIG_HOME/nitrogen/bg-saved.cfg")"
elif type -p gsettings >/dev/null; then
# Get DE if user has disabled the function.
[[ -z "$de" ]] && get_de
case "$de" in
"MATE"*) image="$(gsettings get org.mate.background picture-filename)" ;;
*) image="$(gsettings get org.gnome.desktop.background picture-uri)" ;;
esac
# Strip quotes etc from the path.
image="${image/'file://'}"
image="${image//\'}"
image="${image//\%20/ }"
fi fi
;; ;;
"Mac OS X")
image="$(osascript -e 'tell application "System Events" to picture of current desktop')"
;;
"Windows")
case "$distro" in
"Windows XP")
image="/cygdrive/c/Documents and Settings/${USER}"
image+="/Local Settings/Application Data/Microsoft"
image+="/Wallpaper1.bmp"
;;
"Windows"*)
image="$APPDATA/Microsoft/Windows/Themes"
image+="/TranscodedWallpaper.jpg"
;;
esac
;;
esac esac
# If image is an xml file, don't use it.
[[ "${image/*\./}" == "xml" ]] && image=""
}
get_term_size() {
# This functions gets the current window size in
# pixels.
#
# We first try to use the escape sequence '\044[14t'
# to get the terminal window size in pixels. If this
# fails we then fallback to using 'xdotool' or other
# programs.
# Tmux has a special way of reading escape sequences
# so we have to use a slightly different sequence to
# get the terminal size.
if [[ -n "$TMUX" ]]; then if [[ -n "$TMUX" ]]; then
printf "%b" "\033Ptmux;\033\033[14t\033\033[c\033\\" printf "%b" "\033Ptmux;\033\033[14t\033\033[c\033\\"
read_flags="-d c" read_flags="-d c"
elif [[ "$image_backend" == "tycat" ]]; then elif [[ "$image_program" == "tycat" ]]; then
printf "%b" "\033}qs\000" printf "%b" "\033}qs\000"
else else
...@@ -1950,11 +2027,13 @@ get_image() { ...@@ -1950,11 +2027,13 @@ get_image() {
read_flags="-d c" read_flags="-d c"
fi fi
# The escape code above prints the output AFTER the prompt so this # The escape codes above print the desired output as
# user input so we have to use read to store the out
# -put as a variable.
builtin read -s -t 1 ${read_flags} -r term_size builtin read -s -t 1 ${read_flags} -r term_size
# Split the string # Split the string into height/width.
if [[ "$image_backend" == "tycat" ]]; then if [[ "$image_program" == "tycat" ]]; then
term_size=(${term_size//;/ }) term_size=(${term_size//;/ })
term_width="$((term_size[2] * term_size[0]))" term_width="$((term_size[2] * term_size[0]))"
term_height="$((term_size[3] * term_size[1]))" term_height="$((term_size[3] * term_size[1]))"
...@@ -1969,46 +2048,44 @@ get_image() { ...@@ -1969,46 +2048,44 @@ get_image() {
fi fi
# Get terminal width and height if \033[14t is unsupported. # Get terminal width and height if \033[14t is unsupported.
if (("${#term_size}" <= 5)) && [[ "$image_backend" != "tycat" ]]; then if (("${#term_size}" <= 5)) && [[ "$image_program" == "w3m" ]]; then
if type -p xdotool >/dev/null 2>&1 && \ if type -p xdotool >/dev/null 2>&1; then
[[ "$image_backend" != "iterm2" ]]; then
current_window="$(xdotool getactivewindow)" current_window="$(xdotool getactivewindow)"
source <(xdotool getwindowgeometry --shell "$current_window") source <(xdotool getwindowgeometry --shell "$current_window")
term_height="$HEIGHT" term_height="$HEIGHT"
term_width="$WIDTH" term_width="$WIDTH"
elif type -p xwininfo >/dev/null 2>&1 && \ elif type -p xwininfo >/dev/null 2>&1; then
type -p xdpyinfo >/dev/null 2>&1 || \ # Get the focused window's ID.
type -p xprop >/dev/null 2>&1 && \
[[ "$image_backend" != "iterm2" ]]; then
if type -p xdpyinfo >/dev/null 2>&1; then if type -p xdpyinfo >/dev/null 2>&1; then
current_window="$(xdpyinfo | grep -F "focus" | grep -E -o "0x[0-9a-f]+")" current_window="$(xdpyinfo | grep -F "focus" | grep -E -o "0x[0-9a-f]+")"
elif type -p xprop >/dev/null 2>&1; then elif type -p xprop >/dev/null 2>&1; then
current_window="$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')" current_window="$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')"
fi fi
term_size="$(xwininfo -id "$current_window" | awk -F ': ' '/Width|Height/ {printf $2 " "}')" # If the ID was found get the window size.
term_width="${term_size/ *}" if [[ "$current_window" ]]; then
term_height="${term_size/${term_width}}" term_size="$(xwininfo -id "$current_window" | awk -F ': ' '/Width|Height/ {printf $2 " "}')"
term_width="${term_size/ *}"
term_height="${term_size/${term_width}}"
else
term_width="0"
fi
else
term_width="0"
fi fi
fi fi
# If $img isn't a file fallback to ascii mode. # If the terminal size was found correctly
if [[ ! -f "$img" || -z "$term_width" ]] || (("$term_width" <= 10)); then if [[ "$term_width" ]] && ((term_width > 0)); then
image="ascii"
get_ascii
# Error messages
[[ ! -f "$img" ]] && err "Image: \$img, isn't a file, falling back to ascii mode."
(("${#term_size}" <= 5)) && err "Image: Your terminal doesn't support \\\033[14t, falling back to ascii mode."
return
else
clear clear
zws="​ " zws="​ "
fi fi
}
get_image_size() {
# This functions determines the size to make
# the thumbnail image.
# Get terminal lines and columns # Get terminal lines and columns
term_blocks="$(stty size)" term_blocks="$(stty size)"
...@@ -2019,7 +2096,6 @@ get_image() { ...@@ -2019,7 +2096,6 @@ get_image() {
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
case "$image_size" in case "$image_size" in
"auto") "auto")
image_size="$((columns * font_width / 2))" image_size="$((columns * font_width / 2))"
...@@ -2039,7 +2115,7 @@ get_image() { ...@@ -2039,7 +2115,7 @@ get_image() {
"none") "none")
# Get image size so that we can do a better crop # Get image size so that we can do a better crop
size="$(identify -format "%w %h" "$img")" size="$(identify -format "%w %h" "$image")"
width="${size%% *}" width="${size%% *}"
height="${size##* }" height="${size##* }"
crop_mode="none" crop_mode="none"
...@@ -2048,28 +2124,32 @@ get_image() { ...@@ -2048,28 +2124,32 @@ get_image() {
*) image_size="${image_size/px}" ;; *) image_size="${image_size/px}" ;;
esac esac
# Fallback if width / height are empty.
width="${width:-$image_size}" width="${width:-$image_size}"
height="${height:-$image_size}" height="${height:-$image_size}"
# Padding is half the terminal width + gap text_padding="$((width / font_width + gap + xoffset/font_width))"
padding="\033[$((width / font_width + gap + xoffset/font_width))C" }
# Make the directory if it doesn't exist make_thumbnail() {
mkdir -p "$thumbnail_dir" # Name the thumbnail using variables so we can
# use it later.
image_name="$crop_mode-$crop_offset-$width-$height"
# Check to see if the image has a file extension, if it doesn't # Check to see if the image has a file extension,
# then add one. # if it doesn't then add one.
case "${img##*/}" in case "${image##*/}" in
*"."*) imgname="$crop_mode-$crop_offset-$width-$height-${img##*/}" ;; *"."*) image_name="${image_name}-${image##*/}" ;;
*) imgname="$crop_mode-$crop_offset-$width-$height-${img##*/}.jpg" ;; *) image_name="${image_name}-${image##*/}.jpg" ;;
esac esac
# Check to see if the thumbnail exists before we do any cropping. # Check to see if the thumbnail exists before we do any cropping.
if [[ ! -f "$thumbnail_dir/$imgname" ]]; then if [[ ! -f "$thumbnail_dir/$image_name" ]]; then
# Create the thumbnail dir if it doesn't exist.
mkdir -p "$thumbnail_dir"
# Get image size so that we can do a better crop # Get image size so that we can do a better crop
if [[ -z "$size" ]]; then if [[ -z "$size" ]]; then
size="$(identify -format "%w %h" "$img")" size="$(identify -format "%w %h" "$image")"
og_width="${size%% *}" og_width="${size%% *}"
og_height="${size##* }" og_height="${size##* }"
...@@ -2080,101 +2160,79 @@ get_image() { ...@@ -2080,101 +2160,79 @@ get_image() {
fi fi
case "$crop_mode" in case "$crop_mode" in
fit) "fit")
c="$(convert "$img" \ c="$(convert "$image" \
-colorspace srgb \ -colorspace srgb \
-format "%[pixel:p{0,0}]" info:)" -format "%[pixel:p{0,0}]" info:)"
convert \ convert \
"$img" \ "$image" \
-trim +repage \ -trim +repage \
-gravity south \ -gravity south \
-background "$c" \ -background "$c" \
-extent "$size"x"$size" \ -extent "$size"x"$size" \
-scale "$width"x"$height" \ -scale "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$image_name"
;; ;;
fill) "fill")
convert \ convert \
"$img" \ "$image" \
-trim +repage \ -trim +repage \
-scale "$width"x"$height"^ \ -scale "$width"x"$height"^ \
-extent "$width"x"$height" \ -extent "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$image_name"
;; ;;
none) cp "$img" "$thumbnail_dir/$imgname" ;; "none") cp "$image" "$thumbnail_dir/$image_name" ;;
*) *)
convert \ convert \
"$img" \ "$image" \
-gravity "$crop_offset" \ -gravity "$crop_offset" \
-crop "$size"x"$size"+0+0 \ -crop "$size"x"$size"+0+0 \
-quality 95 \ -quality 95 \
-scale "$width"x"$height" \ -scale "$width"x"$height" \
"$thumbnail_dir/$imgname" "$thumbnail_dir/$image_name"
;; ;;
esac esac
fi fi
# The final image # The final image
img="$thumbnail_dir/$imgname" image="$thumbnail_dir/$image_name"
} }
get_w3m_img_path() { display_image() {
if [[ -x "$w3m_img_path" ]]; then case "$image_program" in
return "w3m")
# Add a tiny delay to fix issues with images not
elif [[ -x "/usr/lib/w3m/w3mimgdisplay" ]]; then # appearing in specific terminal emulators.
w3m_img_path="/usr/lib/w3m/w3mimgdisplay" sleep 0.05
printf "%b\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$image\n4;\n3;" |\
elif [[ -x "/usr/libexec/w3m/w3mimgdisplay" ]]; then "$w3m_img_path" -bg "$background_color" >/dev/null & 2>&1 || to_off "Images: w3m-img failed to display the image."
w3m_img_path="/usr/libexec/w3m/w3mimgdisplay" ;;
elif [[ -x "/usr/lib64/w3m/w3mimgdisplay" ]]; then
w3m_img_path="/usr/lib64/w3m/w3mimgdisplay"
elif [[ -x "/usr/libexec64/w3m/w3mimgdisplay" ]]; then "iterm2")
w3m_img_path="/usr/libexec64/w3m/w3mimgdisplay" printf "%b\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$image")"
;;
else "tycat")
image="ascii" tycat "$image"
err "Image: w3m-img wasn't found on your system, falling back to ascii mode." ;;
fi esac
} }
get_image_backend() { to_ascii() {
if [[ -n "$ITERM_PROFILE" ]]; then # This function makes neofetch fallback to ascii mode.
image_backend="iterm2" image_backend="ascii"
get_ascii 2>/dev/null
elif [[ "$(tycat 2>/dev/null)" ]]; then err "$1"
image_backend="tycat"
else
image_backend="w3m"
fi
} }
display_image() { to_off() {
if [[ "$image" != "ascii" ]]; then # This function makes neofetch fallback to off mode.
case "$image_backend" in text_padding="0"
"w3m") image_backend="off"
# Add a tiny delay to fix issues with images not err "$1"
# appearing in specific terminal emulators.
sleep 0.05
printf "%b\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\
"$w3m_img_path" -bg "$background_color" >/dev/null & 2>&1 || padding="\033[0C"
;;
"iterm2")
printf "%b\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")"
;;
"tycat")
tycat "$img"
;;
esac
fi
} }
# SCREENSHOT # SCREENSHOT
...@@ -2239,7 +2297,7 @@ info() { ...@@ -2239,7 +2297,7 @@ info() {
# If the output is empty, don't print anything. # If the output is empty, don't print anything.
[[ -z "${output// }" ]] && \ [[ -z "${output// }" ]] && \
err "Info: Couldn't detect $subtitle" && return err "Info: Couldn't detect $subtitle." && return
case "$1" in case "$1" in
title) title)
...@@ -2261,7 +2319,7 @@ info() { ...@@ -2261,7 +2319,7 @@ info() {
[[ -z "$2" ]] && string="${string/*: }" [[ -z "$2" ]] && string="${string/*: }"
# Print the string # Print the string
printf "%b\n" "${padding}${zws}${string}${reset} " printf "%b\n" "\033[${text_padding}C${zws}${string}${reset} "
# Calculate info height # Calculate info height
info_height="$((info_height+=1))" info_height="$((info_height+=1))"
...@@ -2269,10 +2327,8 @@ info() { ...@@ -2269,10 +2327,8 @@ info() {
# Fix rendering issues with w3m and lines that # Fix rendering issues with w3m and lines that
# wrap to the next line by adding a max line # wrap to the next line by adding a max line
# length. # length.
if [[ "$image" != "off" && "$image" != "ascii" && "$1" != "cols" ]]; then [[ "$image_backend" == "image" ]] && \
padding_num="${padding/\\033\[}" string="$(printf "%.$((columns - text_padding - gap))s" "$string")"
output="$(printf "%.$((columns - ${padding_num/C} - gap - ${#subtitle}))s" "$output")"
fi
} }
prin() { prin() {
...@@ -2289,7 +2345,7 @@ prin() { ...@@ -2289,7 +2345,7 @@ prin() {
string="$(trim "$string")" string="$(trim "$string")"
# Print the info # Print the info
printf "%b\n" "${padding}${zws}${string}${reset} " printf "%b\n" "\033[${text_padding}C${zws}${string}${reset} "
# Calculate info height # Calculate info height
info_height="$((info_height+=1))" info_height="$((info_height+=1))"
...@@ -2297,10 +2353,8 @@ prin() { ...@@ -2297,10 +2353,8 @@ prin() {
# Fix rendering issues with w3m and lines that # Fix rendering issues with w3m and lines that
# wrap to the next line by adding a max line # wrap to the next line by adding a max line
# length. # length.
if [[ "$image" != "off" && "$image" != "ascii" ]]; then [[ "$image_backend" == "image" ]] && \
padding_num="${padding/\\033\[}" string="$(printf "%.$((columns - text_padding - gap))s" "$string")"
string="$(printf "%.$((columns - ${padding_num/C} - gap))s" "$string")"
fi
# Tell info() that prin() was used. # Tell info() that prin() was used.
prin=1 prin=1
...@@ -2593,13 +2647,6 @@ err() { ...@@ -2593,13 +2647,6 @@ err() {
" "
} }
check_old_flags() {
[[ -n "$osx_buildversion" ]] && err "Config: \$osx_buildversion is deprecated, use \$distro_shorthand instead."
[[ -n "$osx_codename" ]] && err "Config: \$osx_codename is deprecated, use \$distro_shorthand instead."
[[ -n "$progress_char" ]] && err "Config: \$progress_char is deprecated, use \$progress_char_elapsed and \$progress_char_total instead."
[[ "$cpu_cores" == "on" ]] && err "Config: \$cpu_cores='on' is deprecated, use \$cpu_cores='logical|physical|off' instead."
}
get_script_dir() { get_script_dir() {
[[ "$script_dir" ]] && return [[ "$script_dir" ]] && return
...@@ -2635,7 +2682,7 @@ get_default_config() { ...@@ -2635,7 +2682,7 @@ get_default_config() {
fi fi
if source "$default_config"; then if source "$default_config"; then
err "Config: Sourced default config ($default_config)" err "Config: Sourced default config. ($default_config)"
else else
err "Config: Default config not found, continuing..." err "Config: Default config not found, continuing..."
fi fi
...@@ -2645,12 +2692,12 @@ get_user_config() { ...@@ -2645,12 +2692,12 @@ get_user_config() {
# Check $config_file # Check $config_file
if [[ -f "$config_file" ]]; then if [[ -f "$config_file" ]]; then
source "$config_file" source "$config_file"
err "Config: Sourced user config ($config_file)" err "Config: Sourced user config. ($config_file)"
return return
elif [[ "$config_file" == "travis" ]]; then elif [[ "$config_file" == "travis" ]]; then
source "$travis_config" source "$travis_config"
err "Config: Sourced user config ($travis_config)" err "Config: Sourced user config. ($travis_config)"
return return
fi fi
mkdir -p "$XDG_CONFIG_HOME/neofetch/" mkdir -p "$XDG_CONFIG_HOME/neofetch/"
...@@ -2676,7 +2723,7 @@ get_user_config() { ...@@ -2676,7 +2723,7 @@ get_user_config() {
fi fi
source "$config_file" source "$config_file"
err "Config: Sourced user config ($config_file)" err "Config: Sourced user config. ($config_file)"
} }
bar() { bar() {
...@@ -2746,7 +2793,7 @@ get_term_padding() { ...@@ -2746,7 +2793,7 @@ get_term_padding() {
dynamic_prompt() { dynamic_prompt() {
# Calculate image height in terminal cells. # Calculate image height in terminal cells.
if [[ "$image" != "ascii" ]]; then if [[ "$image_backend" != "ascii" ]]; then
get_term_padding 2>/dev/null get_term_padding 2>/dev/null
lines="$(((height + (${border:-0} * 2) + ${yoffset:-0}) / font_height))" lines="$(((height + (${border:-0} * 2) + ${yoffset:-0}) / font_height))"
fi fi
...@@ -2786,6 +2833,14 @@ old_functions() { ...@@ -2786,6 +2833,14 @@ old_functions() {
fi fi
} }
old_flags() {
[[ -n "$osx_buildversion" ]] && err "Config: \$osx_buildversion is deprecated, use \$distro_shorthand instead."
[[ -n "$osx_codename" ]] && err "Config: \$osx_codename is deprecated, use \$distro_shorthand instead."
[[ -n "$progress_char" ]] && err "Config: \$progress_char is deprecated, use \$progress_char_elapsed and \$progress_char_total instead."
[[ "$cpu_cores" == "on" ]] && err "Config: \$cpu_cores='on' is deprecated, use \$cpu_cores='logical|physical|off' instead."
[[ -n "$image" ]] && { err "Config: \$image is deprecated, use \$image_source instead."; image_source="$image"; }
}
cache_uname() { cache_uname() {
# Cache the output of uname so we don't # Cache the output of uname so we don't
# have to spawn it multiple times. # have to spawn it multiple times.
...@@ -3011,8 +3066,8 @@ get_args() { ...@@ -3011,8 +3066,8 @@ get_args() {
# Image # Image
--image) --image)
image="$2" image_source="$2"
case "$2" in "-"* | "") image="ascii" ;; esac case "$2" in "-"* | "") image_backend="ascii" ;; esac
;; ;;
--image_size | --size) image_size="$2" ;; --image_size | --size) image_size="$2" ;;
...@@ -3031,7 +3086,7 @@ get_args() { ...@@ -3031,7 +3086,7 @@ get_args() {
# Ascii # Ascii
--ascii) --ascii)
image="ascii" image_backend="ascii"
ascii="$2" ascii="$2"
case "$2" in "-"* | "") ascii="distro" ;; esac case "$2" in "-"* | "") ascii="distro" ;; esac
;; ;;
...@@ -3048,7 +3103,7 @@ get_args() { ...@@ -3048,7 +3103,7 @@ get_args() {
;; ;;
--ascii_distro) --ascii_distro)
image="ascii" image_backend="ascii"
ascii_distro="$2" ascii_distro="$2"
case "$2" in "-"* | "") ascii_distro="$distro" ;; esac case "$2" in "-"* | "") ascii_distro="$distro" ;; esac
;; ;;
...@@ -3056,7 +3111,7 @@ get_args() { ...@@ -3056,7 +3111,7 @@ get_args() {
--ascii_logo_size) ascii_logo_size="$2" ;; --ascii_logo_size) ascii_logo_size="$2" ;;
--ascii_bold) ascii_bold="$2" ;; --ascii_bold) ascii_bold="$2" ;;
--logo | -L) --logo | -L)
image="ascii" image_backend="ascii"
print_info() { info line_break; } print_info() { info line_break; }
;; ;;
...@@ -3094,7 +3149,7 @@ main() { ...@@ -3094,7 +3149,7 @@ main() {
cache_uname cache_uname
get_os get_os
get_default_config 2>/dev/null get_default_config 2>/dev/null
check_old_flags old_flags
get_args "$@" get_args "$@"
get_distro get_distro
bold bold
...@@ -3109,21 +3164,9 @@ main() { ...@@ -3109,21 +3164,9 @@ main() {
# Hide the cursor and disable line wrap # Hide the cursor and disable line wrap
printf "\033[?25l\033[?7l" printf "\033[?25l\033[?7l"
# Display the image get_image_backend
if [[ "$image" != "off" ]]; then
get_image_backend
# Find w3mimgdisplay
[[ "$image_backend" == "w3m" ]] && \
[[ "$image" != "ascii" ]] && \
get_w3m_img_path
# Get the image src
get_image
# Display the image if enabled
display_image
if [[ "$image_backend" != "off" ]]; then
# Set cursor position next to ascii art # Set cursor position next to ascii art
printf "%b" "\033[$((${lines:-0} - ${prompt_loc:-0}))A" printf "%b" "\033[$((${lines:-0} - ${prompt_loc:-0}))A"
...@@ -3136,12 +3179,12 @@ main() { ...@@ -3136,12 +3179,12 @@ main() {
print_info 2>/dev/null print_info 2>/dev/null
# Prompt calculation # Prompt calculation
if [[ "$image" != "off" ]]; then if [[ "$image_backend" != "off" ]]; then
dynamic_prompt dynamic_prompt
# w3m-img: Draw the image a second time to fix # w3m-img: Draw the image a second time to fix
# rendering issues in specific terminal emulators. # rendering issues in specific terminal emulators.
[[ "$image_backend" == "w3m" ]] && display_image [[ "$image_backend" == "image" && "$image_program" == "w3m" ]] && display_image
fi fi
# Re-enable line wrap # Re-enable line wrap
......
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