Add yes/no validation

This commit is contained in:
Santiago Lo Coco 2022-01-20 00:13:42 -03:00
parent 7f5d913b3c
commit 306024d7b0
1 changed files with 7 additions and 1 deletions

View File

@ -121,7 +121,13 @@ usePlainText() {
printLine
printf '\n%s' "[y/n] "
read -n 1 -r -s readVar
return $([[ "$readVar" =~ ^[Yy]$ ]])
while echo "$readVar" | grep -vqE '[yYnN]'; do
printf "\033[A"
printf '\n%s' "You need to type 'y' or 'n'"
printf '\n%s' "[y/n] "
read -n 1 -r -s readVar
done
[[ "$readVar" =~ ^[Yy]$ ]] && return 0 || return 1
elif [ $msgbox = true ]; then
printLine
printf '\n%s' "Press a key to continue... "