mirror of
https://github.com/php/php-src.git
synced 2025-08-18 15:08:55 +02:00
* add optional default parameter to userDialog method
This commit is contained in:
parent
a9411a6da2
commit
529ec7cda4
1 changed files with 9 additions and 2 deletions
|
@ -25,12 +25,16 @@ class PEAR_CommandUI_CLI extends PEAR
|
|||
print "$text\n";
|
||||
}
|
||||
|
||||
function userDialog($prompt, $type = 'text')
|
||||
function userDialog($prompt, $type = 'text', $default = '')
|
||||
{
|
||||
if ($type == 'password') {
|
||||
system('stty -echo');
|
||||
}
|
||||
print "$prompt : ";
|
||||
print "$prompt ";
|
||||
if ($default) {
|
||||
print "[$default] ";
|
||||
}
|
||||
print ": ";
|
||||
$fp = fopen("php://stdin", "r");
|
||||
$line = fgets($fp, 2048);
|
||||
fclose($fp);
|
||||
|
@ -38,6 +42,9 @@ class PEAR_CommandUI_CLI extends PEAR
|
|||
system('stty echo');
|
||||
print "\n";
|
||||
}
|
||||
if ($default && trim($line) == "") {
|
||||
return $default;
|
||||
}
|
||||
return $line;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue