Prompt the user for input with auto completion.

@param string $question
@param array $choices
@param string $default
@param null $attempts
@param null $strict
@return string
553052
public function askWithCompletion($question, array $choices, $default = null, $attempts = null, $strict = null)
    {
        return $this->output->askWithCompletion($question, $choices, $default, $attempts, $strict);
    }
44132
def ask(self, question, default=False):
        
        choices = '[%s/%s]' % ('Y' if default else 'y', 'n' if default else 'N')
        while True:
            response = raw_input('%s %s' % (question, choices)).strip()
            if not response:
                return default
            elif response in 'yYoO':
                return True
            elif response in 'nN':
                return False
1065921
public function choose($string, array $choices, $useChoiceKeysAsSelector = true) {
        $this->output->writeLine("<question>$string</question>");

        $choicesMap = [];

        foreach ($choices as $subject => $message) {
            if ($useChoiceKeysAsSelector) {
                $index = $subject;
            } else {
                $index = count($choicesMap) + 1;
            }

            $choicesMap[$index] = [
                'subject' => $subject,
                'message' => $message,
            ];
        }

        foreach ($choicesMap as $index => $choice) {
            $message = array_get($choice, 'message');

            $this->output->writeLineIndented("[<yellow>$index</yellow>] $message");
        }

        $choice = null;

        while (true) {
            $this->output->writeIndented('Choice: ');
            $input = $this->input->readLine();

            if (array_has($choicesMap, $input)) {
                $choice = array_get(array_get($choicesMap, $input), 'subject');
                break;
            }

            if ( ! empty($input)) {
                $this->output->writeLineIndented('<yellow>Invalid choice</yellow>');
            }
        }

        return $choice;
    }
1049234
public function ask(string $prompt, array $validAnswers = [], string $default = null)
    {
        if ($validAnswers) {
            $answers = [];
            foreach ($validAnswers as $v) {
                if ($default && $default === $v) {
                    $answers[] = '[' . $v . ']';
                } else {
                    $answers[] = $v;
                }
            }
            $prompt .= ' (' . implode('/', $answers) . ')';
        }

        $prompt .= ' ';

        if ($this->style) {
            echo $this->formatter->getStartMark($this->style);
        }

        $answer = null;
        while (true) {
            $answer = trim($this->console->readLine($prompt));
            if ($validAnswers) {
                if (in_array($answer, $validAnswers, true)) {
                    break;
                }

                if (trim($answer) === '' && $default) {
                    $answer = $default;
                    break;
                }
                continue;
            }
            break;
        }

        if ($this->style) {
            echo $this->formatter->getClearMark();
        }

        return $answer;
    }
175790
protected function askQuestion($question, $choices, $default)
	{
		// Ask until we get a valid response
		do
		{
			echo $question.' '.$choices.': ';
			
			$handle = fopen("php://stdin", "r");
			$line = fgets($handle);

			$response = trim($line);

			// Use default when no response is given
			if (empty($response))
				$response = $default;
		}
		while (!in_array($response, explode('/', $choices)));

		return $response;
	}
1028221
public function ask($name, $prompt, $default = '', $required = false)
    {
        $this->questions[$name] = [
            'prompt' => $prompt,
            'default' => $default,
            'required' => $required,
        ];
    }
64998
final protected function askInput($question, $defaultValue)
    {
        $indent = ($this->indent > 0) ? $this->indent : 0;
        $prompt = empty($defaultValue) && 0 !== $defaultValue ? '' : sprintf(' [<info>%s</info>]', $defaultValue);
        $question = sprintf('%s%s%s: ', str_repeat(' ', 4 * $indent), $question, $prompt);

        $question = new Question($question, $defaultValue);
        return $this->getHelper('question')->ask($this->input, $this->output, $question);
    }
511682
public static function ask(string $question, string $default = '', \Closure $validator = null): ?string
    {
        return self::question($question, $default, $validator);
    }
265918
def user_choice(prompt, choices=("yes", "no"), default=None):
    
    assert default is None or default in choices
    choice_list = ', '.join((choice.title() if choice == default else choice for choice in choices))
    response = None
    while response not in choices:
        response = input(prompt + ' [' + choice_list + ']: ')
        response = response.lower() if response else default
    return response
846633
public function confirmation($message, $choices = ['y' => true, 'n' => false], $default = false)
    {
        $message = is_array($message) ? call_user_func_array('sprintf', $message) : $message;

        $answers = [];
        foreach ($choices as $answer => $value) {
            $answers[$answer] = $answer;
            if ($value === $default) $answers[$answer] = ucfirst($answer);
        }
        
        $this->send(sprintf('%s [%s]: ', $message, join('/', $answers)), '');
        $answer = $this->readline();
        if ($answer === '') return $default;

        if (array_key_exists($answer, $choices)) {
            return $choices[$answer];
        } else {
            foreach ($choices as $key => $value) {
                if ($answer === substr($key, 0, strlen($answer))) return $value;
            }
            return $default;
        }
    }
599492
public function confirm($question, $default = 'yes')
    {
        //Show required message
        echo "\n";
        echo "\t", $this->colorize($question." [$default] ", 'info'); echo " ";
        //Get user input
        $response = trim(fgets(STDIN));
        //Check if $response is yes or not
        if($response == 'yes' || $response == 'no')
        {
            //If is yes or not return the response
            return $response;
        }
        else if(empty($response))
        {
            //If response is empty return default value
            return $default;
        }
        else
        {
            //If not passed argument, repeat confirmation.
            $this->confirm($question, $default);
        }
    }
801488
protected function choice($title, array $choices, $default = false)
    {
        $this->line('Available choices:');

        return cli\menu($choices, $default, $title);
    }
335862
private function askConfirmation(InputInterface $input, OutputInterface $output, $questionText, $default, $separator)
    {
        $questionHelper = $this->getQuestionHelper();

        // NEXT_MAJOR: Remove this BC code for SensioGeneratorBundle 2.3/2.4 after dropping support for Symfony 2.3
        if ($questionHelper instanceof DialogHelper) {
            $question = $questionHelper->getQuestion($questionText, $default, $separator);

            return $questionHelper->askConfirmation($output, $question, ($default === 'no' ? false : true));
        }

        $question = new ConfirmationQuestion($questionHelper->getQuestion(
            $questionText,
            $default,
            $separator
        ), ($default === 'no' ? false : true));

        return $questionHelper->ask($input, $output, $question);
    }
844483
public function askChoice($question, array $options, $allowEmptyChoice = true, $default = null)
    {
        $this->write($this->encloseAsQuestion($question, $default));

        $optionValues = array_values($options);

        foreach ($optionValues as $key => $optionQuestion) {
            $this->write('[' . ($key+1) . ']' . $optionQuestion);               //+1 because normal people prefers 1 over 0 as first option
        }

        $validator = function ($choosenValue) use ($optionValues, $allowEmptyChoice, $default) {
            $isValidValue = isset($optionValues[$choosenValue-1]);
            $isAllowedEmpty = is_null($choosenValue) && $allowEmptyChoice;

            if ($isValidValue) {
                return $choosenValue;
            } elseif ($isAllowedEmpty) {
                return $default;
            }

            throw new InputException('Invalid value (' . $choosenValue . ') provided.');
        };

        $message = 'Choose' . ($allowEmptyChoice ? ' (Hit enter for no choice)' : '');

        $answer = $this->askAndValidate($message, $validator, false, $default);

        if (!is_null($answer)) {
            $optionRealValues = array_keys($options);
            $answer = $optionRealValues[$answer-1];
        }

        return $answer;
    }
1354226
protected function autocomplete()
    {
        $question = new Question(static::PLEASE_SELECT_A_USER);
        $question->setAutocompleterValues($this->userEditor->getChoicesAsSeparateEmailUsername($this->choices));
        $selectedUser = $this->ask($question);
        // nem választott usert, vége
        if ('' === $selectedUser) {
            return;
        }
        $user = $this->getChoiceByUsernameOrEmail($selectedUser);
        // kiválasztott egy usert
        if (!is_null($user)) {
            $this->editor($user);
            // nem választott konkrét usert
        } else {
            $choices = $this->userEditor->getChoices($selectedUser, $selectedUser, true, static::MAX_USER_CHOICES);
            $this->selector($choices);
        }
    }
110316
function prompt(question, isYesDefault) {
  if (typeof isYesDefault !== 'boolean') {
    throw new Error(
      'Provide explicit boolean isYesDefault as second argument.'
    );
  }
  return new Promise(resolve => {
    var rlInterface = rl.createInterface({
      input: process.stdin,
      output: process.stdout,
    });

    var hint = isYesDefault === true ? '[Y/n]' : '[y/N]';
    var message = question + ' ' + hint + '\n';

    rlInterface.question(message, function(answer) {
      rlInterface.close();

      var useDefault = answer.trim().length === 0;
      if (useDefault) {
        return resolve(isYesDefault);
      }

      var isYes = answer.match(/^(yes|y)$/i);
      return resolve(isYes);
    });
  });
}
369116
public static function question(string $question, string $default = '', \Closure $validator = null): string
    {
        return Question::ask($question, $default, $validator);
    }