From 39f552f5894d29396d8e0fd3128106980531ac02 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 6 Jun 2012 15:44:59 +0000 Subject: [PATCH] Improve yes/no decisions. If the user types something wrong, the question will be shown again until he answers yes or no. --- functions.cli | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/functions.cli b/functions.cli index c034fcb5..053a55f4 100644 --- a/functions.cli +++ b/functions.cli @@ -451,18 +451,22 @@ function cli_headline() { } function cli_yesno() { - local message="$@ [y/N] " + local message="$@ [y/n] " local yesno - echo - echo -ne "${message}" - read yesno + while true; do + printf "\n${message}" + read yesno - if listmatch ${yesno} y Y j J yes YES Yes; then - return ${EXIT_OK} - fi + # Check for "yes". + if listmatch ${yesno} y Y yes YES Yes; then + return ${EXIT_TRUE} - return ${EXIT_ERROR} + # Check for "no". + elif listmatch ${yesno} n N no NO No; then + return ${EXIT_FALSE} + fi + done } function cli_get_key() { -- 2.47.3