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");
require_once("services.inc");
require_once("system.inc");
function console_prompt_for_yn($prompt_text)
function console_prompt_for_yn($prompt_text, $default = '')
{
global $fp;
$good_answer = false;
do {
echo "\n" . $prompt_text . " (y/n) ";
$yn = strtolower(chop(fgets($fp)));
if (($yn == "y") || ($yn == "yes")) {
$boolean_answer = true;
$good_answer = true;
}
if (($yn == "n") || ($yn == "no")) {
$boolean_answer = false;
$good_answer = true;
$prompt_yn = sprintf('[%s/%s] ', $default == 'y' ? 'Y' : 'y', $default == 'n' ? 'N' : 'n');
while (true) {
echo "\n{$prompt_text} {$prompt_yn}";
switch (strtolower(chop(fgets($fp)))) {
case 'y':
return true;
case 'n':
return false;
default:
if ($default != '' ) {
return $default == 'y';
}
break;
}
} while (!$good_answer);
return $boolean_answer;
}
}
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