#!/usr/local/bin/cbsd
#v9.1.0
MYARG=""
MYOPTARG="ver arch"
MYDESC="Ncurses based repo interface"

. ${subrdir}/nc.subr
. ${cbsdinit}

DIALOG=${DIALOG=/usr/bin/dialog}
TMPFILE="${ftmpdir}/inputbox.$$"
BACKTITLE="--backtitle \Z1${0}\Zn --colors"

. ${initenv}
. ${tools}
. ${subrdir}/build.subr
. ${cbsdinit}

mainmenu()
{
	while [ 1 ]; do
	$DIALOG ${BACKTITLE} --clear --title "Repo text user interface for v${myversion}" --menu "\n\
select action for ${repo}:" -1 -1 5 \
"menubases" "bases action" \
"menuimages" "images action" \
"EXIT" "EXIT!" 2> ${TMPFILE}
retval=$?

		choice=$( ${CAT_CMD} ${TMPFILE} )
		/bin/rm -f ${TMPFILE}

		case $retval in
			0)
				[ $choice = "menubases" ] && menubases
				[ $choice = "menuimages" ] && menuimages
				[ $choice = "EXIT" ] && exit
				;;
			1)
				err 0 "${N1_COLOR}Cancel pressed.${N0_COLOR}"
				;;
			255)
				[ -z "$choice" ] || echo $choice ;
				echo "ESC pressed."
				exit
				;;
			esac
	done
}


repoaction()
{
	$DIALOG ${BACKTITLE} --clear --title "Repo text user interface for v${myversion}" --menu "\n\
select action for ${repo}:" -1 -1 5 \
"list" "list for ${TARGET}" \
"BACK" "BACK" 2> ${TMPFILE}

	retval=$?

	choice=$( ${CAT_CMD} ${TMPFILE} )
	/bin/rm -f ${TMPFILE}
}

menubases()
{
	TARGET="bases"
	repoaction
	echo $choice
	read p
}


mainmenu
