Skip to content

Commit 520f434

Browse files
committed
Added a note about the behavior of the command question helper
fix symfony/symfony#39946
1 parent 77f2b79 commit 520f434

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

components/console/helpers/questionhelper.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,34 @@ the second argument is not provided, ``true`` is assumed.
6666

6767
The regex defaults to ``/^y/i``.
6868

69+
.. note::
70+
71+
When your output implements ``ConsoleOutputInterface`` the ``stderr`` output is used using :method:`ConsoleOutputInterface::getErrorOutput`.
72+
This output might have a different formatter than the default one. This might lead to unexpected results.
73+
If this is the case, you can apply custom styles directly on to the error output::
74+
75+
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
76+
use Symfony\Component\Console\Question\Question;
77+
use Symfony\Component\Console\Output\ConsoleOutputInterface;
78+
79+
// ...
80+
public function execute(InputInterface $input, OutputInterface $output)
81+
{
82+
// ...
83+
$question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle');
84+
85+
if($questionOutput instanceof ConsoleOutputInterface) {
86+
$questionOutput = $output->getErrorOutput();
87+
}
88+
89+
$outputStyle = new OutputFormatterStyle('red', 'yellow', ['bold', 'blink']);
90+
$questionOutput->getFormatter()->setStyle('fire', $outputStyle);
91+
92+
$bundleName = $helper->ask($input, $questionOutput, $question);
93+
}
94+
95+
More information on formatting can be found on the :doc:`/components/console/helpers/formatterhelper` page.
96+
6997
Asking the User for Information
7098
-------------------------------
7199

0 commit comments

Comments
 (0)