#!/bin/bash
# Derped together by rocket for df. 
#gigi ed.
# Use with decwriter. For setup see setup.txt.
#print line feed to decwriter, default value is 48 rows on the paper
#printf "\x$(printf %x 10)" prints line feed char
#printf "\x$(printf %x 7)" <-- beeps aka bell

function intro() {
	echo 'df Ascii Art printer program'
	printf "\n"
	echo 'menu:'
	printf "\n"
	echo 'A) print a random card'
	printf "\n"
	echo 'B) print cowsay with custom text'
	printf "\n"	
	echo 'C) Print a fortune with ascii art'
	printf "\n"
	echo 'D) Print df logo'
	printf "\n"
	echo 'E) Enter a number(0-20): '
}
DFTXT="Computer club at LU & LTH, http://dflund.se/bli-medlem/"

function printRandom() {
	NUMBER=$((RANDOM%19))
	cat ./d$NUMBER
	printf "\x$(printf %x 10)"
	
}

function cowsayCustom() {
	printf '\n'
	echo 'Type custom text end with enter key(CR):'
	CUSTOMTXT="default"
	read CUSTOMTXT
	cowsay $CUSTOMTXT
	printf "\x$(printf %x 10)"
}

function dragonFortune() {
	printf '\n'
	cowsay -f dragon-and-cow "$(fortune bofh-excuses)"
	printf "\x$(printf %x 10)"
}
function selector() {
	printf '\n'
	echo 'number: '
	read dx
	cat ./d$dx
}

FLAG=true
while $FLAG;
do
	intro
	read choice
	case "$choice" in
		[Aa]) printRandom ;;
		[Bb]) cowsayCustom;;
		[Cc])dragonFortune;;
		[dD]) cat ./d20;;
		[eE]) selector;;
		dfquit) FLAG=false ;;
		*) echo $"Usage: A=random art B=cowsay with text C= dragon & fortune D=df logo E= choose a file number: d[0-20]";;
	esac
done
