Commit e9dbd8fd authored by Franco Fichtner's avatar Franco Fichtner

rc: rework yes/no answer for default value

parent bb3c2cd4
...@@ -36,26 +36,26 @@ require_once("util.inc"); ...@@ -36,26 +36,26 @@ require_once("util.inc");
require_once("services.inc"); require_once("services.inc");
require_once("system.inc"); require_once("system.inc");
function console_prompt_for_yn($prompt_text) function console_prompt_for_yn($prompt_text, $default = '')
{ {
global $fp; global $fp;
$good_answer = false; $prompt_yn = sprintf('[%s/%s] ', $default == 'y' ? 'Y' : 'y', $default == 'n' ? 'N' : 'n');
do { while (true) {
echo "\n" . $prompt_text . " (y/n) "; echo "\n{$prompt_text} {$prompt_yn}";
$yn = strtolower(chop(fgets($fp))); switch (strtolower(chop(fgets($fp)))) {
if (($yn == "y") || ($yn == "yes")) { case 'y':
$boolean_answer = true; return true;
$good_answer = true; case 'n':
return false;
default:
if ($default != '' ) {
return $default == 'y';
}
break;
} }
if (($yn == "n") || ($yn == "no")) {
$boolean_answer = false;
$good_answer = true;
} }
} while (!$good_answer);
return $boolean_answer;
} }
function console_get_interface_from_ppp($realif) function console_get_interface_from_ppp($realif)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment