#!/bin/bash
# Derped together by rocket for df.
# decwriter 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


DFTXT="Computer club at LU & LTH, http://dflund.se/bli-medlem/"

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

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

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

FLAG=true
while $FLAG;
do
	
	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 0-20:";;
	esac
done
