-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Added better interaction for choice questions #11326
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
Conversation
* @throws \InvalidArgumentException | ||
* @throws \RuntimeException | ||
* | ||
* @api |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think putting @api on the class is enough. I mean I would assume it would have methods unshakable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, @api
shoulmd never be added in a PR submitting the code. you cannot make it part of the stable API if it is not even part of the codebase.
We will mark it as part of the stable API only a bit later
I was thinking that this helper could replace the current one for choice questions only when public function ask(InputInterface $input, OutputInterface $output, Question $question)
{
if ($this->hasSttyAvailable() && $question instanceof ChoiceQuestion) {
return $this->helperSet->get('choice_question')
->ask($input, $output, $question);
}
return $this->helperSet->get('generic_question')
->ask($input, $output, $question);
} |
$output->write($text); | ||
|
||
// Move the cursor left | ||
$output->write("\033[10000D"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that here I pull the cursor left of 10 000 columns to avoid using mb_strlen
(maybe less should be enough too).
IMO, it does not mak sense to have a separate helper for choice questions. It makes things harder to use for developers, by requiring to choose the right helper (or they will always use the |
I didn't put it in the What I could do is to put the default handling from https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Console/Helper/QuestionHelper.php#L110 in a separate command like What do you think @stof ? |
I have updated the PR, so it keeps only the |
Btw, it would be nice if someone without |
@@ -24,8 +26,8 @@ | |||
*/ | |||
class QuestionHelper extends Helper | |||
{ | |||
private $options = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like these options. They are making the helper stateful, which is causing issues (it means asking a question in one place will have side effects on next questions in other places).
The configuration should be part of the Question object instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but I think when you want to configure the templates, you want to do it globally for all questions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but here, your options are mutable. This means that some code using the helper can decide to change the options, and this will impact unrelated code (which was expecting to use the defaults).
If the goal is to configure them globally, they should not be mutable by code using the helper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's better to attach them to the Question as you propose. Thanks
This is a great addition, a much better way to give answers, user-friendly 👍 |
👍 |
Thanks for reviewing @stof, I have addressed your comments |
* | ||
* @author Florian Voutzinos <[email protected]> | ||
*/ | ||
interface EscapeSequence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure these utility classes/Interface should actually be in the root of the component (I don't have a good idea for the naming of a subnamespace holding them though).
also, Symfony uses a final class with a private constructor for enums, not an interface (it would not make sense for someone to implement this interface)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe IOUtil
or something like that ?
👍 |
@ro0NL Probably one that you could be interested in taking over :) |
I guess, this PR could be closed after #26698. |
This PR adds a more user friendly way to ask choice questions when
stty
is available.Single choice question
You can move up and down with the arrow keys.
To validate your choice press
enter
.Multi choice question
You can move up and down with the arrow keys.
To select / deselect a choice press the
spacebar
.To validate your choices press
enter
.Todos: