-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
6b73d87
to
e6050fc
Compare
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 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); |
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.
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): |
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.
Please, let's define some constants to avoid these "magic numbers". E.g.:
case self::ARROW_RIGHT === $pressedKey:
// ...
case self::ARROW_LEFT === $pressedKey:
// ...
// ...
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 would highly appreciate that. I read the code and it took some time to dechipher what these numbers are.
Closing as this PR has been in a draft state for many months. Feel free to reopen when it's ready for review. |
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: