10000 [Console] allow multiline responses to console questions · symfony/symfony-docs@e82b66b · GitHub
[go: up one dir, main page]

Skip to content

Commit e82b66b

Browse files
committed
[Console] allow multiline responses to console questions
1 parent 52c2ca0 commit e82b66b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

components/console/helpers/questionhelper.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,36 @@ You can also specify if you want to not trim the answer by setting it directly w
234234
$name = $helper->ask($input, $output, $question);
235235
}
236236

237+
Accept Multiline Answers
238+
~~~~~~~~~~~~~~~~~~~~~~~~
239+
240+
.. versionadded:: 5.2
241+
242+
The ``setMultiline()`` and ``isMultiline()`` methods were introduced in
243+
Symfony 5.2.
244+
245+
By default, the question helper stops reading user input when it receives a newline
246+
character (i.e., when the user hits ``ENTER`` once). However, you may specify that
247+
the response to a question should allow multiline answers by passing ``true`` to
248+
:method:`Symfony\\Component\\Console\\Question\\Question::setMultiline`::
249+
250+
use Symfony\Component\Console\Question\Question;
251+
252+
// ...
253+
public function execute(InputInterface $input, OutputInterface $output)
254+
{
255+
// ...
256+
$helper = $this->getHelper('question');
257+
258+
$question = new Question('How do you solve world peace?');
259+
$question->setMultiline(true);
260+
261+
$answer = $helper->ask($input, $output, $question);
262+
}
263+
264+
Multiline questions stop reading user input after receiving an end-of-transmission
265+
control character (``Ctrl-D`` on Unix systems or ``Ctrl-Z`` on Windows).
266+
237267
Hiding the User's Response
238268
~~~~~~~~~~~~~~~~~~~~~~~~~~
239269

0 commit comments

Comments
 (0)
0