Skip to content

[Console][WIP][POC] Add support for arrow keys in QuestionHelper #36700

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

Closed
wants to merge 1 commit into from

Conversation

pierredup
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #36657
License MIT
Doc PR TBD

Add support for using arrow keys in the QuestionHelper.

The approach here does not depend on readline at all (which had some issues and was removed in #17669)

This PR also solves some of the issues experienced by @javiereguiluz in #15583, as well as supports decorated messages (which readline doesn't, as per #16458 (comment)).

Before I finish the PR, I just want to get some feedback first if this approach is acceptable.

TODO:

  • Fix current tests
  • Add new tests
  • Support arrow keys when question is autocompleted

@pierredup pierredup force-pushed the question-arrow-keys branch from 6b73d87 to e6050fc Compare May 5, 2020 10:11
Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

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

I don't understand the internals of this, so I can't really review it ... but I hope we can fix it this time. It would be great! Thanks @pierredup.

throw new MissingInputException('Aborted.');
}

$k = \ord($ret);
Copy link
Member

Choose a reason for hiding this comment

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

To make this code maintainable in the future, we could rename some variables. E.g. $k -> $pressedKey or $keyCode,etc.

$k = \ord(fgetc($inputStream));

switch (true) {
case 67 === $k && $pos < self::strlen($string):
Copy link
Member

Choose a reason for hiding this comment

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

Please, let's define some constants to avoid these "magic numbers". E.g.:

case self::ARROW_RIGHT === $pressedKey:
    // ...

case self::ARROW_LEFT === $pressedKey:
    // ...

// ...

Choose a reason for hiding this comment

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

I would highly appreciate that. I read the code and it took some time to dechipher what these numbers are.

@nicolas-grekas nicolas-grekas added this to the next milestone May 5, 2020
@fabpot
Copy link
Member

fabpot commented Sep 10, 2020

Closing as this PR has been in a draft state for many months. Feel free to reopen when it's ready for review.

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

Successfully merging this pull request may close these issues.

Console: Support Left/Right Arrow Keys
6 participants