Add usePlainText() and usePlainTextMenu()

This commit is contained in:
Santiago Lo Coco 2022-01-19 18:00:22 -03:00
parent cb43d7a7c1
commit 267a653bf2
1 changed files with 40 additions and 0 deletions

View File

@ -19,6 +19,13 @@ displayDialogBox() {
useDialog "$@"
fi
;;
plain)
if [ "$1" = "--menu" ]; then
usePlainTextMenu "$@"
else
usePlainText "$@"
fi
;;
?)
echo "Unknown dialogBox variable" >&2
exit 1
@ -84,6 +91,39 @@ useWhiptail() {
fi
}
usePlainText() {
inputbox=false; infobox=false; yesnobox=false
for item in "$@"; do
# TODO: Use case
[ "$item" = "--title" ] && shift && shift
[ "$item" = "--inputbox" ] && inputbox=true
[ "$item" = "--infobox" ] && infobox=true
[ "$item" = "--yesno" ] && yesnobox=true
done
printf "$2\n"
if [ $inputbox = true ]; then
read -r readVar
printf "$readVar"
elif [ $yesnobox = true ]; then
printf "[y/n] "
read -n 1 -r readVar
return $([[ "$readVar" =~ ^[Yy]$ ]])
fi
}
usePlainTextMenu() {
menuOptions=(); shift
printf "$1\n"
shift; shift
local i=1; for item in "$@"; do
echo "$item" | grep -qE '[0-9]+' && continue
printf '%s\n' "$i) $item"
((i++))
done
read -n 1 -r readVar
echo "$readVar"
}
getLastArgument() {
local i=0
for i; do :; done