8000 [Console] allow multiline responses to console questions by ramsey · Pull Request #14002 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

8000 [Console] allow multiline responses to console questions #14002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions components/console/helpers/questionhelper.rst
8000
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,36 @@ You can also specify if you want to not trim the answer by setting it directly w
$name = $helper->ask($input, $output, $question);
}

Accept Multiline Answers
~~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 5.2

The ``setMultiline()`` and ``isMultiline()`` methods were introduced in
Symfony 5.2.

By default, the question helper stops reading user input when it receives a newline
character (i.e., when the user hits ``ENTER`` once). However, you may specify that
the response to a question should allow multiline answers by passing ``true`` to
:method:`Symfony\\Component\\Console\\Question\\Question::setMultiline`::

Copy link
Contributor
@noniagriconomie noniagriconomie Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would just add something like:

// src/Command/MyCommand.php

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. I see what you mean now. The context for your comment didn't show the lines below, so I thought you were talking about the lines above. 😁

None of the other examples on this page show an example name for their command script. If I add this here, should I also add it to the rest of the examples?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ho i did not figure that other have not
but yes i see a lot on code example the path file on top as a comment
it helps understanding in which file the class is and its meaning etc :)

but i do not know if you should update all others :s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree, but it's inconsistent with the rest of the examples in this file.

use Symfony\Component\Console\Question\Question;

// ...
public function execute(InputInterface $input, OutputInterface $output)
{
// ...
$helper = $this->getHelper('question');

$question = new Question('How do you solve world peace?');
$question->setMultiline(true);

$answer = $helper->ask($input, $output, $question);
}
Copy link
Contributor
@noniagriconomie noniagriconomie Aug 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing a return here if i am not mistaken, or another // ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied from other examples in the docs, none of which include a return or // ... at the end of the method.


Multiline questions stop reading user input after receiving an end-of-transmission
control character (``Ctrl-D`` on Unix systems or ``Ctrl-Z`` on Windows).

Hiding the User's Response
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
0