Fix read bug

This commit is contained in:
Santiago Lo Coco 2024-04-07 10:20:09 +02:00
parent 011217ee5a
commit d9cc1d4b13
1 changed files with 9 additions and 9 deletions

View File

@ -112,27 +112,27 @@ usePlainText() {
tput sgr0 tput sgr0
if [ $inputbox = true ]; then if [ $inputbox = true ]; then
printLine && printf "\n" printLine && printf "\n"
read -r readVar read -r readVar < /dev/tty
printf '%s' "$readVar" 1>&2 printf '%s' "$readVar" 1>&2
elif [ $passwordbox = true ]; then elif [ $passwordbox = true ]; then
printLine && printf "\n" printLine && printf "\n"
read -r -s readVar read -r -s readVar < /dev/tty
printf '%s' "$readVar" 1>&2 printf '%s' "$readVar" 1>&2
elif [ $yesno = true ]; then elif [ $yesno = true ]; then
printLine printLine
printf '\n%s' "[y/n] " printf '\n%s' "[y/n] "
read -n 1 -r -s readVar read -n 1 -r -s readVar < /dev/tty
while echo "$readVar" | grep -vqE '[yYnN]'; do while echo "$readVar" | grep -vqE '[yYnN]'; do
printf "\033[A" printf "\033[A"
printf '\n%s' "You need to type 'y' or 'n'" printf '\n%s' "You need to type 'y' or 'n'"
printf '\n%s' "[y/n] " printf '\n%s' "[y/n] "
read -n 1 -r -s readVar read -n 1 -r -s readVar < /dev/tty
done done
[[ "$readVar" =~ ^[Yy]$ ]] && return 0 || return 1 [[ "$readVar" =~ ^[Yy]$ ]] && return 0 || return 1
elif [ $msgbox = true ]; then elif [ $msgbox = true ]; then
printLine printLine
printf '\n%s' "Press a key to continue... " printf '\n%s' "Press a key to continue... "
read -n 1 -r -s read -n 1 -r -s < /dev/tty
fi fi
} }
@ -148,12 +148,12 @@ usePlainTextMenu() {
done done
printLine printLine
printf '\n%s' "[1..$((i-1))] " printf '\n%s' "[1..$((i-1))] "
read -n ${#i} -r readVar read -n ${#i} -r -s readVar < /dev/tty
while echo "$readVar" | grep -vqE '[0-9]+' || [[ $readVar -le 0 || $readVar -ge $i ]]; do while echo "$readVar" | grep -vqE '[0-9]+' || [[ $readVar -le 0 || $readVar -ge $i ]]; do
printf "\033[A" printf "\033[A"
printf '\n%s' "You need to choose a number between 1 and $((i-1))" printf '\n%s' "You need to choose a number between 1 and $((i-1))"
printf '\n%s' "[1..$((i-1))] " printf '\n%s' "[1..$((i-1))] "
read -n 1 -r -s readVar read -n ${#i} -r -s readVar < /dev/tty
done done
printf "\n" printf "\n"
printf '%s' "$readVar" 1>&2 printf '%s' "$readVar" 1>&2
@ -182,13 +182,13 @@ usePlainTextList() {
isNewline=false isNewline=false
selectedOptions=() selectedOptions=()
while [ $isNewline = false ]; do while [ $isNewline = false ]; do
read -n ${#j} -r readVar read -n ${#j} -r -s readVar < /dev/tty
while echo "$readVar" | grep -vqE '[0-9]+' || [[ $readVar -le 0 || $readVar -gt $j ]]; do while echo "$readVar" | grep -vqE '[0-9]+' || [[ $readVar -le 0 || $readVar -gt $j ]]; do
[ "${#readVar}" -eq 0 ] && isNewline=true && break [ "${#readVar}" -eq 0 ] && isNewline=true && break
printf "\033[A" printf "\033[A"
printf '\n%s' "You need to choose a number between 1 and $j)" printf '\n%s' "You need to choose a number between 1 and $j)"
printf '\n%s' "[1..$j] " printf '\n%s' "[1..$j] "
read -n 1 -r -s readVar read -n ${#j} -r -s readVar < /dev/tty
done done
[ $isNewline = true ] && break [ $isNewline = true ] && break
clear clear