#!/usr/bin/env bash # ANSI Retro Tool (art) for Linux # Version 2.0 (02 Jan 2026) - Blue Oak Model License 1.0.0 # Project page: https://640kb.neocities.org/apps/apps.html # Notes: The "--fconvert" flag performs the same function as "--convert" but # adds special ANSI sequences (clear screen, position cursor) and a # standardized footer with viewing instructions. # # This is a basic ANSI viewer. Some files may not display correctly. # It was created specifically to automate posting ANSI art to # ansi@happynetbox.com and to make files Linux-terminal compatible. # More info: https://640kb.neocities.org/ascii/art.hnb.html if [ $# -eq 0 ]; then echo "" echo " .----------------------------------------------------------------------." echo " | ANSI Retro Tool (art) |" echo " | --------------------- |" echo " | A homemade ANSI Art viewer and CP437-to-UTF-8 converter built from |" echo " | standard Linux tools: iconv, sed, echo -e and cat |" echo " | |" echo " | Usage: art [OPTION] |" echo " | |" echo " | Options: |" echo " | --convert Save converted UTF-8 version as |" echo " | |" echo " | --fconvert Preps ANSI for posting to .plan |" echo " | (adds clear screen, cursor positioning and footer) |" echo " | |" echo " | --reset Reset terminal colors and clear screen |" echo " | |" echo " | Examples: |" echo " | art (no options) Display this help |" echo " | art file.ans Display ANSI Art to stdout |" echo " | art --convert file.ans Generate file.ans.converted (UTF-8) |" echo " | art --fconvert file.ans Generate file.ans.fconverted (UTF-8) |" echo " | ready for posting |" echo " | |" echo " | Note: ANSI files should be CP437 encoded for correct display |" echo " '----------------------------------------------------------------------'" echo "" exit 1 fi CONVERT_MODE=false FCONVERT_MODE=false INPUT_FILE="" if [ "$1" = "--convert" ]; then CONVERT_MODE=true INPUT_FILE="$2" elif [ "$1" = "--fconvert" ]; then FCONVERT_MODE=true INPUT_FILE="$2" elif [ "$1" = "--reset" ]; then printf "\033c" exit 0 else INPUT_FILE="$1" fi if [ ! -f "$INPUT_FILE" ]; then echo "Error: File '$INPUT_FILE' not found!" exit 1 fi TEMP_FILE=$(mktemp /tmp/ansi_converted_XXXXXX.txt) if [ $? -ne 0 ]; then echo "Error: Could not create temporary file" exit 1 fi if [ "$CONVERT_MODE" = true ]; then OUTPUT_FILE="${INPUT_FILE}.converted" elif [ "$FCONVERT_MODE" = true ]; then OUTPUT_FILE="${INPUT_FILE}.fconverted" else OUTPUT_FILE="" fi if [ -n "$OUTPUT_FILE" ] && [ -f "$OUTPUT_FILE" ] && { [ "$CONVERT_MODE" = true ] || [ "$FCONVERT_MODE" = true ]; }; then read -p "Overwrite existing file $OUTPUT_FILE? [y/N] " -n 1 -r echo "" if [[ ! $REPLY =~ ^[Yy]$ ]]; then echo "Conversion cancelled" rm -f "$TEMP_FILE" exit 0 fi fi if ! iconv -f CP437 -t UTF-8//IGNORE "$INPUT_FILE" > "$TEMP_FILE"; then echo "Error: Conversion failed! Is iconv installed?" rm -f "$TEMP_FILE" exit 1 fi sed -i 's/\x1b/\\e/g' "$TEMP_FILE" if [ "$CONVERT_MODE" = true ]; then cp "$TEMP_FILE" "$OUTPUT_FILE" echo "" echo "Converted file saved as: $OUTPUT_FILE" echo "" elif [ "$FCONVERT_MODE" = true ]; then TEMP_FCONVERT=$(mktemp /tmp/ansi_fconverted_XXXXXX.txt) printf '%s' '\e[2J\e[H\e[E\e[E' > "$TEMP_FCONVERT" cat "$TEMP_FILE" >> "$TEMP_FCONVERT" echo "-------------------------------------------------------------------------------" >> "$TEMP_FCONVERT" echo "* view: curl -s gopher://happynetbox.com:79/0ansi | head -n -2 | echo -e \"\$(cat)\"" >> "$TEMP_FCONVERT" echo "* info: https://640kb.neocities.org/ascii/art.hnb.html" >> "$TEMP_FCONVERT" echo '\e[s\e[3A\e[0J' >> "$TEMP_FCONVERT" cp "$TEMP_FCONVERT" "$OUTPUT_FILE" rm -f "$TEMP_FCONVERT" echo "" echo "F-Converted file saved as: $OUTPUT_FILE" echo "" else echo "" echo -e "$(cat "$TEMP_FILE")" echo "" fi [ -f "$TEMP_FILE" ] && rm -f "$TEMP_FILE"