#!/usr/bin/env bash

# Read in language
source ${BBROOTDIR}/lang/${BBLANG}/iso_menu.lang

# Read in functions
source ${BBROOTDIR}/func/isofunc.sh
source ${BBROOTDIR}/misc/commonfunctions.sh

####PROGRAM START#####
while true; do
        # This is for the numbering of the menu choices. It is
        # updated once before each entry printout in the menu
        # except exit which should always be 0. The variable must
	# be reset within this while loop or bad things will happen.
        (( bb_m_c = 0 ))
        # <colors>
	#source "$BBROOTDIR"/misc/colors.idx
        # </colors>
    clear
        # <table>
    echo -e "${BBTABLECOLOR}${BBDECOLINE}"
    echo -e "${BBTABLECOLOR}|${BBHEADCOLOR} ${BBVERSION} ${BBTABLECOLOR}|"
    echo -e "${BBTABLECOLOR}${BBDECOLINE}"
    echo -e "${BBTABLECOLOR}|"
    echo -e "${BBTABLECOLOR}|-(${BBSUBCOLOR}$bb_im_menu_title${BBTABLECOLOR})"
	(( bb_m_c += 1 ))
    echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_im_menu_1"
	(( bb_m_c += 1 ))
    echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_im_menu_2${BBBURNDIR}"
	(( bb_m_c += 1 ))
    echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_im_menu_3"
	(( bb_m_c += 1 ))
    echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_im_menu_4"
	(( bb_m_c += 1 ))
    echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} $bb_m_c) $bb_im_menu_5"
    echo -e "${BBTABLECOLOR}|${BBMAINCOLOR} 0) $bb_im_menu_0"
    echo -e "${BBTABLECOLOR}|"
    echo -n -e "${BBINPUTCOLOR}$bb_im_menu_entry[0-$bb_m_c] |>${BBMAINCOLOR} "
    read action
    echo -e "${BBCOLOROFF}"
        # </table>
    
    case $action in
	1)      # Burn ISO
	    ${BBROOTDIR}/burning/burning.sh --iso
	    ;;
	2)	#Create ISO from BBBURNDIR
	    create_iso_from_dir
	    ;;
	3)	# Create ISO from cd
	    create_iso_from_cd
	    ;;
	4)      # Burn DVD image
	    ${BBROOTDIR}/burning/burning.sh --dvdimage
	    ;;
	5)	# Mount image in a loopback device
	    mount_in_loopback
	    ;;
	0)      # Quit
	    break
	    ;;
	*)	#You chose wrong stupid!
	    echo "$bb_im_error[0-$bb_m_c]"
	    wait_for_enter
	    continue
	    ;;
    esac
done


syntax highlighted by Code2HTML, v. 0.9.1