You are here

protected function SymfonyQuestionHelper::writePrompt in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/console/Helper/SymfonyQuestionHelper.php \Symfony\Component\Console\Helper\SymfonyQuestionHelper::writePrompt()

Outputs the question prompt.

Parameters

OutputInterface $output:

Question $question:

Overrides QuestionHelper::writePrompt

File

vendor/symfony/console/Helper/SymfonyQuestionHelper.php, line 53

Class

SymfonyQuestionHelper
Symfony Style Guide compliant question helper.

Namespace

Symfony\Component\Console\Helper

Code

protected function writePrompt(OutputInterface $output, Question $question) {
  $text = $question
    ->getQuestion();
  $default = $question
    ->getDefault();
  switch (true) {
    case null === $default:
      $text = sprintf(' <info>%s</info>:', $text);
      break;
    case $question instanceof ConfirmationQuestion:
      $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
      break;
    case $question instanceof ChoiceQuestion:
      $choices = $question
        ->getChoices();
      $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $choices[$default]);
      break;
    default:
      $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, $default);
  }
  $output
    ->writeln($text);
  if ($question instanceof ChoiceQuestion) {
    $width = max(array_map('strlen', array_keys($question
      ->getChoices())));
    foreach ($question
      ->getChoices() as $key => $value) {
      $output
        ->writeln(sprintf("  [<comment>%-{$width}s</comment>] %s", $key, $value));
    }
  }
  $output
    ->write(' > ');
}