Last active
March 13, 2025 06:55
-
-
Save xero/04b9446e57a578e550e19cc17be29325 to your computer and use it in GitHub Desktop.
display ansi art in your terminal - a CP437 to UTF-8 converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ansi art converter | |
help() { | |
echo "Usage: $0 <path-to-ans-file>" | |
echo "Example: $0 ~/docs/ansi/x0-krad.ans" | |
exit 1 | |
} | |
deps() { | |
local dependencies=("iconv" "awk" "perl") | |
for dep in "${dependencies[@]}"; do | |
if ! command -v "$dep" &> /dev/null; then | |
echo "error: Required dependency '$dep' is not installed." | |
exit 1 | |
fi | |
done | |
} | |
breaks() { | |
perl -pe 's/\r\n/\n/g' "$1" | head -c -128 | |
} | |
colors() { | |
perl -pe ' | |
s/\e\[1;30m/\e[0;90m/g; | |
s/\e\[1;31m/\e[0;91m/g; | |
s/\e\[1;32m/\e[0;92m/g; | |
s/\e\[1;33m/\e[0;93m/g; | |
s/\e\[1;34m/\e[0;94m/g; | |
s/\e\[1;35m/\e[0;95m/g; | |
s/\e\[1;36m/\e[0;96m/g; | |
s/\e\[1;37m/\e[0;97m/g; | |
' | |
} | |
convert() { | |
iconv -f CP437 -t UTF-8 | |
} | |
# error trapping | |
deps | |
[ $# -ne 1 ] && help | |
[ ! -f "$1" ] && { | |
echo "error: file not found!" | |
help | |
} | |
# parser logic | |
breaks "$1" | convert | colors |
Author
xero
commented
Mar 13, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment