Add an exit option to ask dialog

This commit is contained in:
Juno Takano 2024-08-31 07:56:41 -03:00
parent 85151e1de6
commit a0fdbe0149

View file

@ -68,14 +68,15 @@ ask() {
dialog_options="$dialog_options\n [$options_count] $option" dialog_options="$dialog_options\n [$options_count] $option"
done; done;
IFS= IFS=
dialog_options="$dialog_options\n [0] Exit"
printf "%s" "$question" >&2 printf "%s" "$question" >&2
printf "%b" "$dialog_options" >&2 printf "%b" "$dialog_options" >&2
printf "\n%s" "Choose an option [1-$options_count] " >&2 printf "\n%s" "Choose an option number: " >&2
read -r read_answer read -r read_answer
answer="$(echo "$read_answer" | xargs)" answer="$(echo "$read_answer" | xargs)"
if [ "$answer" -gt 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then if [ "$answer" -ge 0 ] 2> /dev/null && [ "$answer" -le $options_count ]; then
echo "$answer" echo "$answer"
else else
log debug "[ask] Invalid choice" log debug "[ask] Invalid choice"