Get ascii size in a single wc call

This commit is contained in:
Dylan 2016-03-29 17:57:22 +11:00
parent 059eb0eec0
commit 5c6b680a1e

View file

@ -1852,15 +1852,14 @@ getascii () {
export LC_ALL="$SYS_LOCALE" export LC_ALL="$SYS_LOCALE"
# Turn the file into a variable and strip escape codes. # Turn the file into a variable and strip escape codes.
ascii_strip=$(<"$ascii") ascii_strip=$(<"${ascii}")
ascii_strip=${ascii_strip//\$\{??\}} ascii_strip=${ascii_strip//\$\{??\}}
ascii_strip=${ascii_strip//\\} ascii_strip=${ascii_strip//\\}
# Get length of longest line # Get length of longest line
length="$(wc -L 2>/dev/null <<< "$ascii_strip")" ascii_size=($(wc -lL 2>/dev/null <<< "$ascii_strip"))
ascii_length=${ascii_size[0]}
# Get the height in lines ascii_height=${ascii_size[1]}
lines="$(($(wc -l 2>/dev/null <<< "$ascii_strip") + 1))"
# Fallback to using awk on systems without 'wc -L' # Fallback to using awk on systems without 'wc -L'
[ -z "$length" ] && \ [ -z "$length" ] && \
@ -2851,7 +2850,7 @@ if [ "$image" != "off" ]; then
[ -z "$info_height" ] && info_height=0 [ -z "$info_height" ] && info_height=0
# Set cursor position dynamically based on height of ascii/text. # Set cursor position dynamically based on height of ascii/text.
[ "$lines" -lt "$info_height" ] && lines="$info_height" [ "$ascii_length" -lt "$info_height" ] && lines="$info_height"
printf "%b%s" "\033[${lines}H\033[${prompt_height}A" printf "%b%s" "\033[${lines}H\033[${prompt_height}A"
fi fi