Simplify parts of the image functions
This commit is contained in:
parent
abd6692019
commit
6cdbf9ca21
59
fetch
59
fetch
|
@ -1311,7 +1311,7 @@ getstyle () {
|
||||||
case "$os" in
|
case "$os" in
|
||||||
"Windows")
|
"Windows")
|
||||||
[ -z "$path" ] && return
|
[ -z "$path" ] && return
|
||||||
theme="$(head -n1 $path 2>/dev/null)"
|
theme="$(head -n1 "$path" 2>/dev/null)"
|
||||||
theme="${theme##*\\}"
|
theme="${theme##*\\}"
|
||||||
theme="${theme%.*}"
|
theme="${theme%.*}"
|
||||||
theme="${theme^}"
|
theme="${theme^}"
|
||||||
|
@ -1783,8 +1783,6 @@ getascii () {
|
||||||
|
|
||||||
# Turn the file into a variable.
|
# Turn the file into a variable.
|
||||||
ascii_strip=$(<"$ascii")
|
ascii_strip=$(<"$ascii")
|
||||||
|
|
||||||
# Strip escape codes backslashes from contents of
|
|
||||||
ascii_strip=${ascii_strip//\$\{??\}}
|
ascii_strip=${ascii_strip//\$\{??\}}
|
||||||
ascii_strip=${ascii_strip//\\}
|
ascii_strip=${ascii_strip//\\}
|
||||||
|
|
||||||
|
@ -1798,13 +1796,9 @@ getascii () {
|
||||||
[ -z "$length" ] && \
|
[ -z "$length" ] && \
|
||||||
length="$(awk 'length>max{max=length}END{print max}' <<< "$ascii_strip")"
|
length="$(awk 'length>max{max=length}END{print max}' <<< "$ascii_strip")"
|
||||||
|
|
||||||
# Set the text padding
|
|
||||||
padding="\033[$((length + gap))C"
|
padding="\033[$((length + gap))C"
|
||||||
|
|
||||||
# Print the ascii
|
|
||||||
printf "%b%s" "$print"
|
printf "%b%s" "$print"
|
||||||
|
|
||||||
# Set locale to get correct padding
|
|
||||||
export LC_ALL=C
|
export LC_ALL=C
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1824,34 +1818,21 @@ ascii_colors () {
|
||||||
|
|
||||||
getimage () {
|
getimage () {
|
||||||
# Fallback to ascii mode if imagemagick isn't installed.
|
# Fallback to ascii mode if imagemagick isn't installed.
|
||||||
if ! type -p convert >/dev/null 2>&1; then
|
type -p convert >/dev/null 2>&1 || image="ascii"
|
||||||
image="ascii"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Call function based on $image
|
# Call function based on $image
|
||||||
case "$image" in
|
case "$image" in
|
||||||
"wall")
|
"wall") getwallpaper ;;
|
||||||
getwallpaper
|
"shuffle") img="$(find "$shuffle_dir" -type f \( -name '*.jpg' -o -name '*.png' \) -print0 | shuf -n1 -z)" ;;
|
||||||
;;
|
"ascii") getascii; return ;;
|
||||||
|
*) img="$image" ;;
|
||||||
"shuffle")
|
|
||||||
img="$(find "$shuffle_dir" -type f \( -name '*.jpg' -o -name '*.png' \) -print0 |
|
|
||||||
shuf -n1 -z)"
|
|
||||||
;;
|
|
||||||
|
|
||||||
"ascii")
|
|
||||||
getascii
|
|
||||||
return
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
img="$image"
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Get terminal width and height
|
# Get terminal width and height
|
||||||
printf "%b%s" '\033[14t'
|
printf "%b%s" '\033[14t'
|
||||||
|
|
||||||
|
# The ascape code above prints the output AFTER the prompt so this
|
||||||
|
# loop below reads it as input. wtf xterm
|
||||||
index=0
|
index=0
|
||||||
while IFS= read -s -r -n 1 -t 0.25 char; do
|
while IFS= read -s -r -n 1 -t 0.25 char; do
|
||||||
case "$index" in
|
case "$index" in
|
||||||
|
@ -1864,10 +1845,8 @@ getimage () {
|
||||||
# If $img isn't a file or the terminal doesn't support xterm escape sequences,
|
# If $img isn't a file or the terminal doesn't support xterm escape sequences,
|
||||||
# fallback to ascii mode.
|
# fallback to ascii mode.
|
||||||
if [ ! -f "$img" ] || [ -z "$term_height" ]; then
|
if [ ! -f "$img" ] || [ -z "$term_height" ]; then
|
||||||
# Fallback to ascii mode
|
|
||||||
image="ascii"
|
image="ascii"
|
||||||
getascii
|
getascii
|
||||||
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -1903,18 +1882,11 @@ getimage () {
|
||||||
# Make the directory if it doesn't exist
|
# Make the directory if it doesn't exist
|
||||||
mkdir -p "$thumbnail_dir"
|
mkdir -p "$thumbnail_dir"
|
||||||
|
|
||||||
# Check to see if the image has a file extension
|
# Check to see if the image has a file extension, if it doesn't
|
||||||
|
# then add one.
|
||||||
case "${img##*/}" in
|
case "${img##*/}" in
|
||||||
*"."*)
|
*"."*) imgname="$crop_mode-$crop_offset-$image_size-${img##*/}" ;;
|
||||||
# Get name of image and prefix it with it's crop mode and offset
|
*) imgname="$crop_mode-$crop_offset-$image_size-${img##*/}.jpg" ;;
|
||||||
imgname="$crop_mode-$crop_offset-$image_size-${img##*/}"
|
|
||||||
;;
|
|
||||||
|
|
||||||
*)
|
|
||||||
# Add a file extension if the image doesn't have one. This
|
|
||||||
# fixes w3m not being able to display them.
|
|
||||||
imgname="$crop_mode-$crop_offset-$image_size-${img##*/}.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.
|
||||||
|
@ -1926,11 +1898,8 @@ getimage () {
|
||||||
|
|
||||||
# This checks to see if height is geater than width
|
# This checks to see if height is geater than width
|
||||||
# so we can do a better crop of portrait images.
|
# so we can do a better crop of portrait images.
|
||||||
if [ "$height" -gt "$width" ]; then
|
size=$height
|
||||||
size=$width
|
[ "$height" -gt "$width" ] && size=$width
|
||||||
else
|
|
||||||
size=$height
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$crop_mode" in
|
case "$crop_mode" in
|
||||||
fit)
|
fit)
|
||||||
|
|
Reference in New Issue