]> granicus.if.org Git - php/commitdiff
* add optional default parameter to userDialog method
authorStig Bakken <ssb@php.net>
Tue, 19 Mar 2002 19:28:48 +0000 (19:28 +0000)
committerStig Bakken <ssb@php.net>
Tue, 19 Mar 2002 19:28:48 +0000 (19:28 +0000)
pear/PEAR/CommandUI/CLI.php

index 816abde4b408ed285a551209427caea33194b041..76ea6f6baf4e6b0f7139ac31c0ecafab9756922f 100644 (file)
@@ -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;
     }