first swap menus

This commit is contained in:
Marc Beninca 2023-11-23 19:29:33 +01:00
parent 738c2095d2
commit 86d12fe01f
5 changed files with 67 additions and 24 deletions

View file

@ -31,11 +31,13 @@ function env_apply {
fi
}
function env_default {
if [ "${1}" == 'check_squashfs' ] ; then default="_${check_squashfs}" ; fi
if [ "${1}" == 'live_from' ] ; then default="_${live_from}" ; fi
if [ "${1}" == 'pause' ] ; then default="_${pause}" ; fi
if [ "${1}" == 'time_out' ] ; then default="_${time_out}" ; fi
function env_get {
unset get
if [ "${1}" == 'check_squashfs' ] ; then get="${check_squashfs}" ; fi
if [ "${1}" == 'live_from' ] ; then get="${live_from}" ; fi
if [ "${1}" == 'pause' ] ; then get="${pause}" ; fi
if [ "${1}" == 'time_out' ] ; then get="${time_out}" ; fi
if [ ! "${get}" ] ; then return 1 ; fi
}
function env_init {

View file

@ -8,11 +8,20 @@ function menu {
}
function menu_color {
menu_item \
setparams \
'black' 'blue' 'green' 'cyan' \
'red' 'magenta' 'brown' 'light-gray' \
'dark-gray' 'light-blue' 'light-green' 'light-cyan' \
'light-red' 'light-magenta' 'yellow' 'white'
for color in "${@}" ; do
menu_item "${color}"
done
unset color
}
function menu_exit {
env save
menu
}
function menu_init {
@ -25,19 +34,26 @@ function menu_init {
fi
menu_split
default=2
if env_get "${menu}" ; then
default="_${get}"
unset get
fi
fi
}
function menu_item {
env_default "${menu}"
for item in "${@}" ; do
menuentry "${item}" "${menu}" --id "_${item}" {
${2}="${1}"
env save
menu
if [ "${1}" ] ; then
if [ "${2}" ] ; then
entry="${2}"
else
entry="${1}"
fi
menuentry "${entry}" "${1}" "${menu}" --id "_${1}" {
${3}="${2}"
menu_exit
}
done
unset item
unset entry
fi
}
function menu_load {
@ -53,3 +69,19 @@ function menu_split {
menuentry '' { nop }
fi
}
function menu_swap {
if [ "${4}" ] ; then
menuentry "${1}" "${2}" "${3}" "${4}" {
if env_get "${2}" ; then
if [ "${get}" == "${3}" ] ; then
${2}="${4}"
else
${2}="${3}"
fi
unset get
menu_exit
fi
}
fi
}