Input/Keyboard.php
/**
     * Reads one line from the keyboard. Will accept all printable characters.
     * You can set a mask of which characters to accept.
     *
     * @param string    $prompt The prompt to display.
     * @param char|bool $echo   True | False if you want characters to be printed as typed
     *                          on the keyboard. You can also pass a character that should be
     *                          echoed instead, useful for password input, eg "*"
     * @param string    $mask   A mask of which characters to accept. Accepts any valid regex
     *                          charset, eg "a-zA-Z", "\d", "\p{L}", "[:print:] etc.
     * @access public
     * @return string
     */
Reads one line from the keyboard. Will accept all printable characters.
You can set a mask of which characters to accept.

@param string    $prompt The prompt to display.
@param char|bool $echo   True | False if you want characters to be printed as typed
on the keyboard. You can also pass a character that should be
echoed instead, useful for password input, eg "*"
@param string    $mask   A mask of which characters to accept.
Reads one line from the keyboard . Will accept all printable characters . You can set a mask of which characters to accept . @param string $prompt The prompt to display . @param char|bool $echo True | False if you want characters to be printed as typed on the keyboard . You can also pass a character that should be echoed instead useful for password input eg " * " @param string $mask A mask of which characters to accept .
public function readLine($prompt = ': ', $echo = true, $mask = null)
    {
        $input  = array();
        $key    = $this->getKeys();
        $char   = null;
        $cursor = 0;
        if (!$mask) {
            $mask = '\p{L}[:print:]';
        }
        echo $prompt;
        while (true) {
            $char = $this->readChar(
                $mask,
                array(
                    $key::ENTER,
                    $key::BACKSPACE,
                    $key::TAB,
                    $key::ESC,
                )
            );
            switch ($char) {
                case $key::ENTER:
                    break 2;
                case $key::ESC:
                    return false;
                case $key::BACKSPACE:
                    if ($cursor > 0) {
                        array_pop($input);
                        $cursor--;
                        if ($echo !== false) {
                            echo "\x08 \x08";
                        }
                    }
                    break;
                case $key::TAB:
                    $count = count($input);
                    echo $this->_getAutoComplete($input);
                    echo $prompt . implode('', $input);
                    $cursor += count($input) - $count;
                    break;
                default:
                    $cursor++;
                    array_push($input, $char);
                    if ($echo !== false) {
                        echo is_string($echo) ? $echo : $char;
                    }
                    break;
            }
        }
        return implode('', $input);
    }
public function readLine ( $ prompt = ': ' , $ echo = true , $ mask = null ) { $ input = array ( ) ; $ key = $ this -> getKeys ( ) ; $ char = null ; $ cursor = 0 ; if ( ! $ mask ) { $ mask = '\p{L}[:print:]' ; } echo $ prompt ; while ( true ) { $ char = $ this -> readChar ( $ mask , array ( $ key :: ENTER , $ key :: BACKSPACE , $ key :: TAB , $ key :: ESC , ) ) ; switch ( $ char ) { case $ key :: ENTER : break 2 ; case $ key :: ESC : return false ; case $ key :: BACKSPACE : if ( $ cursor > 0 ) { array_pop ( $ input ) ; $ cursor -- ; if ( $ echo !== false ) { echo " \x08 \x08 " ; } } break ; case $ key :: TAB : $ count = count ( $ input ) ; echo $ this -> _getAutoComplete ( $ input ) ; echo $ prompt . implode ( '' , $ input ) ; $ cursor += count ( $ input ) - $ count ; break ; default : $ cursor ++ ; array_push ( $ input , $ char ) ; if ( $ echo !== false ) { echo is_string ( $ echo ) ? $ echo : $ char ; } break ; } } return implode ( '' , $ input ) ; }
Reads one line from the keyboard.
Reads one line from the keyboard .