From c63fafe77597f24648feb0fd2a571e10e97c9b1d Mon Sep 17 00:00:00 2001 From: Artem Stepin Date: Wed, 13 Jul 2022 23:11:40 +0200 Subject: [PATCH] Added a note about the behavior of the command question helper fix https://github.com/symfony/symfony/issues/39946 --- components/console/helpers/questionhelper.rst | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/console/helpers/questionhelper.rst b/components/console/helpers/questionhelper.rst index ff15953dc06..9622022d9e8 100644 --- a/components/console/helpers/questionhelper.rst +++ b/components/console/helpers/questionhelper.rst @@ -66,6 +66,34 @@ the second argument is not provided, ``true`` is assumed. The regex defaults to ``/^y/i``. +.. note:: + + When your output implements ``ConsoleOutputInterface`` the ``stderr`` output is used using :method:`ConsoleOutputInterface::getErrorOutput`. + This output might have a different formatter than the default one. This might lead to unexpected results. + If this is the case, you can apply custom styles directly on to the error output:: + + use Symfony\Component\Console\Formatter\OutputFormatterStyle; + use Symfony\Component\Console\Output\ConsoleOutputInterface; + use Symfony\Component\Console\Question\Question; + + // ... + public function execute(InputInterface $input, OutputInterface $output) + { + // ... + $question = new Question('Please enter the name of the bundle', 'AcmeDemoBundle'); + + if($output instanceof ConsoleOutputInterface) { + $output = $output->getErrorOutput(); + } + + $outputStyle = new OutputFormatterStyle('red', 'yellow', ['bold', 'blink']); + $output->getFormatter()->setStyle('fire', $outputStyle); + + $bundleName = $helper->ask($input, $output, $question); + } + + More information on formatting can be found on the :doc:`/components/console/helpers/formatterhelper` page. + Asking the User for Information -------------------------------