note 19129 deleted from function.readline by hholzgra

From: Date: Thu, 02 Aug 2012 12:38:12 +0000
Subject: note 19129 deleted from function.readline by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189685@lists.php.net to get a copy of this message
Note Submitter: don at undesigned dot org dot za ---- This might help some of you a bit: /* example for how to return console colours - same as normal console colours with chr(27) for ^[ - returns 0 to reset if null */ function cl($str = 0) { return (chr(27) . "[" . $str . "m"); } /* check user input for readline() (uses $default if given), asks for it again if user input is null and $default not specified. */ function readline_add($str,$default = null) { for ($i = 0; $i < 1; $i++) { if ($default !== null) { $line = readline(cl("1;31") . $str . cl("1;37") . " [$default]: "); if (isset($line) && $line !== "") { readline_add_history($line); /* add history */ } else { readline_add_history($default); /* add default to history */ } } else { $line = readline(cl("1;31") . $str . cl("1;37") . ": "); if (isset($line) && $line !== "") { readline_add_history($line); /* add history */ } else { $i -= 1; /* we -1 to repeat the query if input is null */ } } } } readline_add("one"); /* $history[0] - if no input is given, it asks for it again */ readline_add("two","bla"); /* $history[1] - if no input is given it defaults to "bla" */ /* readline_list_history() returns an array so handle it how you wish */ $history = readline_list_history(); print "One: " . $history[0] . "\n"; print "Two: " . $history[1] . "\n"; print cl(); /* reset colours with 0 */

« previous php.notes (#189685) next »