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

[Console] Added better interaction for choice questions #11326

Open
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
@florianv
Contributor

florianv commented Jul 5, 2014

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This PR adds a more user friendly way to ask choice questions when stty is available.

Single choice question

single

You can move up and down with the arrow keys.
To validate your choice press enter.

Multi choice question

multi

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:

  • Finish tests
  • Documentation
@florianv

This comment has been minimized.

Show comment
Hide comment
@florianv

florianv Jul 7, 2014

Contributor

I was thinking that this helper could replace the current one for choice questions only when stty is available. This could be done by renaming QuestionHelper into GenericQuestionHelper for example, and then creating a new QuestionHelper that just proxies the other two:

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);
}
Contributor

florianv commented Jul 7, 2014

I was thinking that this helper could replace the current one for choice questions only when stty is available. This could be done by renaming QuestionHelper into GenericQuestionHelper for example, and then creating a new QuestionHelper that just proxies the other two:

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);
}
@stof

This comment has been minimized.

Show comment
Hide comment
@stof

stof Jul 8, 2014

Member

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 question helper they already know, and users will not benefit from the better experience).
The enhanced experience should be implemented in the QuestionHelper directly (using the existing logic when you don't have stty)

Member

stof commented Jul 8, 2014

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 question helper they already know, and users will not benefit from the better experience).
The enhanced experience should be implemented in the QuestionHelper directly (using the existing logic when you don't have stty)

@florianv

This comment has been minimized.

Show comment
Hide comment
@florianv

florianv Jul 8, 2014

Contributor

I didn't put it in the QuestionHelper because I feared it becomes a mess with the different handlings (for example they write the questions and choices differently). On the other side the choice question handling is mostly done by the SingleChoiceQuestionAsker and the MultiChoiceQuestionAsker.

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 GenericQuestionAsker to keep the QuestionHelper clean. It will choose the appropriate Asker depending on the type of question and if stty is available and use that directly.

What do you think @stof ?

Contributor

florianv commented Jul 8, 2014

I didn't put it in the QuestionHelper because I feared it becomes a mess with the different handlings (for example they write the questions and choices differently). On the other side the choice question handling is mostly done by the SingleChoiceQuestionAsker and the MultiChoiceQuestionAsker.

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 GenericQuestionAsker to keep the QuestionHelper clean. It will choose the appropriate Asker depending on the type of question and if stty is available and use that directly.

What do you think @stof ?

@florianv florianv changed the title from [Console] Added a new helper for choice questions to [Console] Added better interaction for choice questions Jul 11, 2014

@florianv

This comment has been minimized.

Show comment
Hide comment
@florianv

florianv Jul 11, 2014

Contributor

I have updated the PR, so it keeps only the QuestionHelper and uses the new way when stty is available and it's a choice question. I have also completed the tests.

Contributor

florianv commented Jul 11, 2014

I have updated the PR, so it keeps only the QuestionHelper and uses the new way when stty is available and it's a choice question. I have also completed the tests.

@florianv

This comment has been minimized.

Show comment
Hide comment
@florianv

florianv Jul 11, 2014

Contributor

Btw, it would be nice if someone without stty could run the tests.

Contributor

florianv commented Jul 11, 2014

Btw, it would be nice if someone without stty could run the tests.

@florianv

This comment has been minimized.

Show comment
Hide comment
@florianv

florianv Jul 17, 2014

Contributor

What do you think about this PR ? @fabpot @stof

Contributor

florianv commented Jul 17, 2014

What do you think about this PR ? @fabpot @stof

@eko

This comment has been minimized.

Show comment
Hide comment
@eko

eko Jul 17, 2014

Contributor

This is a great addition, a much better way to give answers, user-friendly 👍

Contributor

eko commented Jul 17, 2014

This is a great addition, a much better way to give answers, user-friendly 👍

@mickaelandrieu

This comment has been minimized.

Show comment
Hide comment
@mickaelandrieu

mickaelandrieu Jul 17, 2014

Contributor

👍

Contributor

mickaelandrieu commented Jul 17, 2014

👍

@florianv

This comment has been minimized.

Show comment
Hide comment
@florianv

florianv Jul 17, 2014

Contributor

Thanks for reviewing @stof, I have addressed your comments

Contributor

florianv commented Jul 17, 2014

Thanks for reviewing @stof, I have addressed your comments

protected $question;
protected $choicesMap;
public function __construct(ChoiceQuestion $question)

This comment has been minimized.

@ProPheT777

ProPheT777 Jul 17, 2014

Contributor

Missing phpdocs

@ProPheT777

ProPheT777 Jul 17, 2014

Contributor

Missing phpdocs

This comment has been minimized.

@florianv

florianv Jul 17, 2014

Contributor

IMO it's not needed

@florianv

florianv Jul 17, 2014

Contributor

IMO it's not needed

This comment has been minimized.

@fabpot

fabpot Jul 17, 2014

Member

Correct, not needed as there is a type hint on the argument.

@fabpot

fabpot Jul 17, 2014

Member

Correct, not needed as there is a type hint on the argument.

$output->write(sprintf(EscapeSequences::CURSOR_MOVE_BACKWARD_N, 10000));
}
private function doAsk(OutputInterface $output, ChoicesCursor $cursor, $inputStream)

This comment has been minimized.

@ProPheT777

ProPheT777 Jul 17, 2014

Contributor

Same here

@ProPheT777

ProPheT777 Jul 17, 2014

Contributor

Same here

This comment has been minimized.

@florianv

florianv Jul 17, 2014

Contributor

Afaik private methods are not documented unless there is ambiguity (but here the argument names are quite descriptive already)

@florianv

florianv Jul 17, 2014

Contributor

Afaik private methods are not documented unless there is ambiguity (but here the argument names are quite descriptive already)

This comment has been minimized.

@fabpot

fabpot Jul 17, 2014

Member

correct, not needed

@fabpot

fabpot Jul 17, 2014

Member

correct, not needed

@ProPheT777

This comment has been minimized.

Show comment
Hide comment
@ProPheT777

ProPheT777 Jul 17, 2014

Contributor

👍

Contributor

ProPheT777 commented Jul 17, 2014

👍

@florianv

This comment has been minimized.

Show comment
Hide comment
@florianv

florianv Oct 31, 2014

Contributor

Any new about this PR @fabpot @stof ?

Contributor

florianv commented Oct 31, 2014

Any new about this PR @fabpot @stof ?

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Dec 6, 2016

@nicolas-grekas nicolas-grekas modified the milestones: 3.4, 4.1 Sep 28, 2017

@chalasr chalasr self-requested a review Feb 5, 2018

@fabpot

This comment has been minimized.

Show comment
Hide comment
@fabpot

fabpot Mar 31, 2018

Member

@ro0NL Probably one that you could be interested in taking over :)

Member

fabpot commented Mar 31, 2018

@ro0NL Probably one that you could be interested in taking over :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment