Pure bash solution to getting ascii size, don't run tput in ascii mode and supress config and script dir errors

This commit is contained in:
Dylan 2016-05-15 09:10:37 +10:00
parent b1a7707df7
commit 8a55245442

View file

@ -2102,7 +2102,7 @@ getascii () {
ascii="/usr/local/share/neofetch/ascii/distro/${ascii/ *}" ascii="/usr/local/share/neofetch/ascii/distro/${ascii/ *}"
else else
getscriptdir getscriptdir 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
@ -2136,9 +2136,12 @@ getascii () {
ascii_strip=${ascii_strip//\\} ascii_strip=${ascii_strip//\\}
# Get length of longest line # Get length of longest line
ascii_size=($(awk 'END {print NR}length>max{max=length}END{print max}' <<< "$ascii_strip")) # Get lines/columns of the ascii file in pure bash.
lines=$((ascii_size[0] + 1)) while read -r line 2>/dev/null; do
ascii_length=${ascii_size[1]} [ ${#line} -gt ${ascii_length:-0} ] && ascii_length=${#line}
lines=$((lines+=1))
done <<< "$ascii_strip"
lines=$((lines+=1))
padding="\033[$((ascii_length + gap))C" padding="\033[$((ascii_length + gap))C"
printf "%b%s" "$print" printf "%b%s" "$print"
@ -2155,9 +2158,6 @@ getimage () {
# Fallback to ascii mode if imagemagick isn't installed. # Fallback to ascii mode if imagemagick isn't installed.
type -p convert >/dev/null 2>&1 || image="ascii" type -p convert >/dev/null 2>&1 || image="ascii"
# Get terminal lines
lines=$(tput lines)
case "$image" in case "$image" in
"wall") getwallpaper ;; "wall") getwallpaper ;;
"ascii") getascii; return ;; "ascii") getascii; return ;;
@ -2205,6 +2205,9 @@ getimage () {
return return
fi fi
# Get terminal lines
lines=$(tput lines)
# Get terminal columns # Get terminal columns
columns=$(tput cols) columns=$(tput cols)
@ -2745,7 +2748,7 @@ case "$@" in
config="off" config="off"
;; ;;
esac esac
[ "$config" == "on" ] && getconfig [ "$config" == "on" ] && getconfig 2>/dev/null
# }}} # }}}
@ -3100,7 +3103,7 @@ while [ "$1" ]; do
--config) --config)
case "$2" in case "$2" in
"none" | "off") config="off" ;; "none" | "off") config="off" ;;
*) config_file="$2"; config="on"; getconfig ;; *) config_file="$2"; config="on"; getconfig 2>/dev/null ;;
esac esac
;; ;;
--test) --test)