Skip to content

Instantly share code, notes, and snippets.

@Doridian
Last active August 4, 2024 00:47
Show Gist options
  • Select an option

  • Save Doridian/b174690a3f2e8e9990ce8a85944415b1 to your computer and use it in GitHub Desktop.

Select an option

Save Doridian/b174690a3f2e8e9990ce8a85944415b1 to your computer and use it in GitHub Desktop.
#!/usr/bin/ash
# SPDX-License-Identifier: GPL-2.0-only
# https://github.com/TheZoraiz/ascii-image-converter
# COLORTERM=24bit ascii-image-converter --color ./art.png -c > /etc/dori-logo/logo.txt
run_hook() {
# Print blank line to ensure we don't merge lines together
echo ''
TERM_W="$(tput cols)"
#TERM_H="$(tput lines)"
source /etc/dori-logo/logo.env
if [ -z "$TERM_W" ]; then
TERM_W="$(echo "$TERM_SIZE_FALLBACK" | cut -d' ' -f2)"
fi
#if [ -z "$TERM_H" ]; then
# TERM_H="$(echo "$TERM_SIZE_FALLBACK" | cut -d' ' -f1)"
#fi
# Get image width
IMG_WIDTH=1
while read LINE; do
ROW_WIDTH="$(echo "$LINE" | sed 's,\x1B\[[0-9;]*[a-zA-Z],,g' | wc -c)"
if [ $ROW_WIDTH -gt $IMG_WIDTH ]; then
IMG_WIDTH="$ROW_WIDTH"
fi
done < /etc/dori-logo/logo.txt
# Calculate coords
X=$(( $TERM_W - $IMG_WIDTH ))
Y=0
# Print image guaded by tput sc/rc to not affect cursor
tput sc
while read LINE; do
tput cup $Y $X
Y=$(( $Y + 1 ))
echo "$LINE"
done < /etc/dori-logo/logo.txt
tput rc
}
# vim: set ft=sh ts=4 sw=4 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment