PluginProbe
Depicter — Popup & Slider Builder / trunk
Depicter — Popup & Slider Builder vtrunk
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / symfony / console / Helper / SymfonyQuestionHelper.php

SymfonyQuestionHelper.php in Depicter — Popup & Slider Builder trunk, at vendor/symfony/console/Helper/SymfonyQuestionHelper.php

110 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Console\Helper;
13
14 use Symfony\Component\Console\Formatter\OutputFormatter;
15 use Symfony\Component\Console\Output\OutputInterface;
16 use Symfony\Component\Console\Question\ChoiceQuestion;
17 use Symfony\Component\Console\Question\ConfirmationQuestion;
18 use Symfony\Component\Console\Question\Question;
19 use Symfony\Component\Console\Style\SymfonyStyle;
20
21 /**
22 * Symfony Style Guide compliant question helper.
23 *
24 * @author Kevin Bond <[email protected]>
25 */
26 class SymfonyQuestionHelper extends QuestionHelper
27 {
28 /**
29 * {@inheritdoc}
30 */
31 protected function writePrompt(OutputInterface $output, Question $question)
32 {
33 $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
34 $default = $question->getDefault();
35
36 if ($question->isMultiline()) {
37 $text .= sprintf(' (press %s to continue)', $this->getEofShortcut());
38 }
39
40 switch (true) {
41 case null === $default:
42 $text = sprintf(' <info>%s</info>:', $text);
43
44 break;
45
46 case $question instanceof ConfirmationQuestion:
47 $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
48
49 break;
50
51 case $question instanceof ChoiceQuestion && $question->isMultiselect():
52 $choices = $question->getChoices();
53 $default = explode(',', $default);
54
55 foreach ($default as $key => $value) {
56 $default[$key] = $choices[trim($value)];
57 }
58
59 $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default)));
60
61 break;
62
63 case $question instanceof ChoiceQuestion:
64 $choices = $question->getChoices();
65 $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default] ?? $default));
66
67 break;
68
69 default:
70 $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default));
71 }
72
73 $output->writeln($text);
74
75 $prompt = ' > ';
76
77 if ($question instanceof ChoiceQuestion) {
78 $output->writeln($this->formatChoiceQuestionChoices($question, 'comment'));
79
80 $prompt = $question->getPrompt();
81 }
82
83 $output->write($prompt);
84 }
85
86 /**
87 * {@inheritdoc}
88 */
89 protected function writeError(OutputInterface $output, \Exception $error)
90 {
91 if ($output instanceof SymfonyStyle) {
92 $output->newLine();
93 $output->error($error->getMessage());
94
95 return;
96 }
97
98 parent::writeError($output, $error);
99 }
100
101 private function getEofShortcut(): string
102 {
103 if ('Windows' === \PHP_OS_FAMILY) {
104 return '<comment>Ctrl+Z</comment> then <comment>Enter</comment>';
105 }
106
107 return '<comment>Ctrl+D</comment>';
108 }
109 }
110