ascii: simplify handling.

This commit is contained in:
Dylan Araps 2018-06-03 10:14:53 +10:00
parent bee887a3e0
commit d69fd6d839

View file

@ -3364,39 +3364,31 @@ image_backend() {
} }
get_ascii() { get_ascii() {
if [[ ! -f "$image_source" ]]; then if [[ -f "$image_source" ]]; then
err "Ascii: Ascii file not found, using distro ascii."
else
ascii_data="$(< "$image_source")" ascii_data="$(< "$image_source")"
else
err "Ascii: Ascii file not found, using distro ascii."
fi fi
# Set locale to get correct padding. # Set locale to get correct padding.
LC_ALL="$sys_locale" LC_ALL="$sys_locale"
# Turn file into variable.
while IFS=$'\n' read -r line; do
print+="$line
"
# Calculate size of ascii file in line length / line count. # Calculate size of ascii file in line length / line count.
line="${line//[??;?;??m}" while IFS=$'\n' read -r line; do
line="${line//[??;?;???m}"
line="${line//}"
line="${line//\$\{??\}}"
line="${line//\\\\/\\}"
((${#line} > ascii_length)) && ascii_length="${#line}" ((${#line} > ascii_length)) && ascii_length="${#line}"
((++lines)) ((++lines))
done <<< "$ascii_data" done <<< "${ascii_data//\$\{??\}}"
# Colors. # Colors.
print="${print//\$\{c1\}/$c1}" ascii_data="${ascii_data//\$\{c1\}/$c1}"
print="${print//\$\{c2\}/$c2}" ascii_data="${ascii_data//\$\{c2\}/$c2}"
print="${print//\$\{c3\}/$c3}" ascii_data="${ascii_data//\$\{c3\}/$c3}"
print="${print//\$\{c4\}/$c4}" ascii_data="${ascii_data//\$\{c4\}/$c4}"
print="${print//\$\{c5\}/$c5}" ascii_data="${ascii_data//\$\{c5\}/$c5}"
print="${print//\$\{c6\}/$c6}" ascii_data="${ascii_data//\$\{c6\}/$c6}"
((text_padding=ascii_length+gap)) ((text_padding=ascii_length+gap))
printf "%b" "$print" printf '%b\n' "$ascii_data"
LC_ALL=C LC_ALL=C
} }
@ -6694,7 +6686,7 @@ EOF
"nixos_small") "nixos_small")
set_colors 4 6 set_colors 4 6
read -rd '' ascii_data <<'EOF' read -rd '' ascii_data <<'EOF'
${c1}\\\\ \\\\ // ${c1} \\\\ \\\\ //
==\\\\__\\\\/ // ==\\\\__\\\\/ //
// \\\\// // \\\\//
==// //== ==// //==
@ -6823,7 +6815,7 @@ EOF
"OpenBSD"*) "OpenBSD"*)
set_colors 3 7 6 1 8 set_colors 3 7 6 1 8
read -rd '' ascii_data <<'EOF' read -rd '' ascii_data <<'EOF'
${c3} _ ${c3} _
(_) (_)
${c1} | . ${c1} | .
${c1} . |L /| . ${c3} _ ${c1} . |L /| . ${c3} _