Exemple #1
0
 /**
  * 显示问题的提示信息
  */
 protected function writePrompt()
 {
     $text = $this->question->getQuestion();
     $default = $this->question->getDefault();
     switch (true) {
         case null === $default:
             $text = sprintf(' <info>%s</info>:', $text);
             break;
         case $this->question instanceof Confirmation:
             $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
             break;
         case $this->question instanceof Choice && $this->question->isMultiselect():
             $choices = $this->question->getChoices();
             $default = explode(',', $default);
             foreach ($default as $key => $value) {
                 $default[$key] = $choices[trim($value)];
             }
             $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, implode(', ', $default));
             break;
         case $this->question instanceof Choice:
             $choices = $this->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);
     }
     $this->output->writeln($text);
     if ($this->question instanceof Choice) {
         $width = max(array_map('strlen', array_keys($this->question->getChoices())));
         foreach ($this->question->getChoices() as $key => $value) {
             $this->output->writeln(sprintf("  [<comment>%-{$width}s</comment>] %s", $key, $value));
         }
     }
     $this->output->write(' > ');
 }