################################################################################
#whiptail_test.sh
################################################################################
#By: Julian Zelazny

#TODO:
#check that all files exist before trying to use them

#set -x

#===============================================================================
#Print out the message in the PIOP_Message.txt file
#===============================================================================

function printPIOPMessages {

processedText=

while read -r inputString; do
  processedText+=(${inputString}\\n);
done < PIOP_Message.txt

whiptail --msgbox --scrolltext "$(echo "${processedText[@]}")" $(stty size)
}

#===============================================================================
#QX-MAP test
#===============================================================================

# RUN QX TEST HERE and pipe results to script or file
# replace 'cat PIOP-QX.MAP' with the test program

function runQXTest {

result=failure
dataArray=
qxTestCommand='cat PIOP-QX.MAP'


#run the test and compare with known good output
if $(${qxTestCommand} | cmp -s PIOP-QX.MAP - ); then
  result=success
fi

#replace all the hex values with printable characters
#and get rid of pesky new lines (RAGE)
dataArray=$(${qxTestCommand} | od -An -w32 -v -t x1 | tr -d "\n" |\
sed \
-e 's/00/ /g' \
-e 's/02/X/g' \
-e 's/03/*/g' \
-e 's/[0-9A-Fa-f][0-9A-Fa-f]/?/g')

whiptail --msgbox "\
QX result ${result}        1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3\\n\
 F = 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\\n\
A00:${dataArray:0:64}\\n\
A01:${dataArray:64:64}\\n\
A02:${dataArray:128:64}\\n\
A03:${dataArray:192:64}\\n\
A04:${dataArray:256:64}\\n\
A05:${dataArray:320:64}\\n\
A06:${dataArray:384:64}\\n\
A07:${dataArray:448:64}\\n\
A08:${dataArray:512:64}\\n\
A09:${dataArray:576:64}\\n\
A10:${dataArray:640:64}\\n\
A11:${dataArray:704:64}\\n\
A12:${dataArray:768:64}\\n\
A13:${dataArray:832:64}\\n\
A14:${dataArray:896:64}\\n\
A15:${dataArray:960:64}\\n\
" $(stty size)
}

#===============================================================================
#PIOP Main Menu
#===============================================================================

printPIOPMessages

menuChoice=$(whiptail \
--title "Menu Title" \
--menu "Menu Text " $(stty size) 8 \
"1" "QX test" \
"2" "Option 2" \
"3" "Option 3" \
"4" "Option 4" \
"5" "Option 5" \
"6" "Option 6" \
"7" "Option 7" \
"8" "Option 8" \
3>&1 1>&2 2>&3)

#echo "${menuChoice}"

case $menuChoice in
  1)
    runQXTest
    ;;
  2)
    echo "option 2"
    ;;
  3)
    echo "option 3"
    ;;
  4)
    echo "option 4"
    ;;
  5)
    echo "option 5"
    ;;
  6)
    echo "option 6"
    ;;
  7)
    echo "option 7"
    ;;
  8)
    echo "option 8"
    ;;
  esac





























