* add optional default parameter to userDialog method

This commit is contained in:
Stig Bakken 2002-03-19 19:28:48 +00:00
parent a9411a6da2
commit 529ec7cda4

View file

@ -25,12 +25,16 @@ class PEAR_CommandUI_CLI extends PEAR
print "$text\n"; print "$text\n";
} }
function userDialog($prompt, $type = 'text') function userDialog($prompt, $type = 'text', $default = '')
{ {
if ($type == 'password') { if ($type == 'password') {
system('stty -echo'); system('stty -echo');
} }
print "$prompt : "; print "$prompt ";
if ($default) {
print "[$default] ";
}
print ": ";
$fp = fopen("php://stdin", "r"); $fp = fopen("php://stdin", "r");
$line = fgets($fp, 2048); $line = fgets($fp, 2048);
fclose($fp); fclose($fp);
@ -38,6 +42,9 @@ class PEAR_CommandUI_CLI extends PEAR
system('stty echo'); system('stty echo');
print "\n"; print "\n";
} }
if ($default && trim($line) == "") {
return $default;
}
return $line; return $line;
} }