Added patch from dylanaraps/neofetch/1220 as it runs faster in some instances and does not hinder performance where it doesn't work
This commit is contained in:
parent
86e266e5b7
commit
cb32928102
1 changed files with 23 additions and 2 deletions
25
neofetch
25
neofetch
|
@ -3862,6 +3862,26 @@ image_backend() {
|
||||||
[[ "$image_backend" != "off" ]] && printf '\e[%sA\e[9999999D' "${lines:-0}"
|
[[ "$image_backend" != "off" ]] && printf '\e[%sA\e[9999999D' "${lines:-0}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# From pull request #1220, this is a fast way to strip character codes
|
||||||
|
strip_escape_codes() {
|
||||||
|
local input="${1//\"/\\\"}" output="" i char within_code=0
|
||||||
|
for ((i=0; i < ${#input}; ++i)); do
|
||||||
|
char="${input:i:1}"
|
||||||
|
if (( within_code == 1 )); then
|
||||||
|
case "${char}" in
|
||||||
|
[a-zA-Z]) within_code=0 ;;
|
||||||
|
esac
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
if [[ "${char}" == $'\e' ]]; then
|
||||||
|
within_code=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
output+="${char}"
|
||||||
|
done
|
||||||
|
eval "$2=\"${output}\""
|
||||||
|
}
|
||||||
|
|
||||||
print_ascii() {
|
print_ascii() {
|
||||||
if [[ -f "$image_source" && ! "$image_source" =~ (png|jpg|jpeg|jpe|svg|gif) ]]; then
|
if [[ -f "$image_source" && ! "$image_source" =~ (png|jpg|jpeg|jpe|svg|gif) ]]; then
|
||||||
ascii_data="$(< "$image_source")"
|
ascii_data="$(< "$image_source")"
|
||||||
|
@ -3876,9 +3896,10 @@ print_ascii() {
|
||||||
|
|
||||||
# Calculate size of ascii file in line length / line count.
|
# Calculate size of ascii file in line length / line count.
|
||||||
while IFS=$'\n' read -r line; do
|
while IFS=$'\n' read -r line; do
|
||||||
line=${line//\\\\/\\}
|
|
||||||
line=${line//█/ }
|
line=${line//█/ }
|
||||||
# Use patterns to replace color codes
|
# This method to strip escape codes doesn't always work but is faster in some cases if run first
|
||||||
|
strip_escape_codes "${line}" line
|
||||||
|
# Use patterns to replace color codes that the above line did not catch
|
||||||
line=${line//\\033\[*([0-9;])[JKmsu]/}
|
line=${line//\\033\[*([0-9;])[JKmsu]/}
|
||||||
line=${line//\[*([0-9;])[JKmsu]/}
|
line=${line//\[*([0-9;])[JKmsu]/}
|
||||||
((++lines,${#line}>ascii_len)) && ascii_len="${#line}"
|
((++lines,${#line}>ascii_len)) && ascii_len="${#line}"
|
||||||
|
|
Loading…
Reference in a new issue