public function prompt(string $text, $default = null, callable $fn = null, int $retry = 3)
    {
        $error = 'Invalid value. Please try again!';

        $this->writer->yellow($text)->comment(null !== $default ? " [$default]: " : ': ');

        try {
            $input = $this->reader->read($default, $fn);
        } catch (\Exception $e) {
            $error = $e->getMessage();
        }

        if ($retry > 0 && (isset($e) || \strlen($input ?? '') === 0)) {
            $this->writer->bgRed($error, true);

            return $this->prompt($text, $default, $fn, $retry - 1);
        }

        return $input ?? $default;
    }
public function prompt(string $text, $default = null, callable $fn = null, int $retry = 3)
    {
        $error = 'Invalid value. Please try again!';

        $this->writer->yellow($text)->comment(null !== $default ? " [$default]: " : ': ');

        try {
            $input = $this->reader->read($default, $fn);
        } catch (\Exception $e) {
            $error = $e->getMessage();
        }

        if ($retry > 0 && (isset($e) || \strlen($input ?? '') === 0)) {
            $this->writer->bgRed($error, true);

            return $this->prompt($text, $default, $fn, $retry - 1);
        }

        return $input ?? $default;
    }
public function prompt ( string $ text , $ default = null , callable $ fn = null , int $ retry = 3 ) { $ error = 'Invalid value. Please try again!' ; $ this -> writer -> yellow ( $ text ) -> comment ( null !== $ default ? " [$default]: " : ': ' ) ; try { $ input = $ this -> reader -> read ( $ default , $ fn ) ; } catch ( \ Exception $ e ) { $ error = $ e -> getMessage ( ) ; } if ( $ retry > 0 && ( isset ( $ e ) || \ strlen ( $ input ?? '' ) === 0 ) ) { $ this -> writer -> bgRed ( $ error , true ) ; return $ this -> prompt ( $ text , $ default , $ fn , $ retry - 1 ) ; } return $ input ?? $ default ; }
Prompt user for free input.

@param string        $text    Prompt text.
@param mixed         $default
@param callable|null $fn      The sanitizer/validator for user input
Any exception message is printed and prompted again.
@param int           $retry   How many more times to retry on failure.

@return mixed
Prompt user for free input .