From: Stig Bakken Date: Tue, 19 Mar 2002 19:28:48 +0000 (+0000) Subject: * add optional default parameter to userDialog method X-Git-Tag: php-4.3.0dev-ZendEngine2-Preview1~1217 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=529ec7cda45f2f11dc74700e4cea533d115baf72;p=php * add optional default parameter to userDialog method --- diff --git a/pear/PEAR/CommandUI/CLI.php b/pear/PEAR/CommandUI/CLI.php index 816abde4b4..76ea6f6baf 100644 --- a/pear/PEAR/CommandUI/CLI.php +++ b/pear/PEAR/CommandUI/CLI.php @@ -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; }