Skip to content
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] Support a set of control keys and key combinations in QuestionHelper #48287

Open
wants to merge 1 commit into
base: 6.3
Choose a base branch
from

Conversation

maxbeckers
Copy link
Contributor

@maxbeckers maxbeckers commented Nov 22, 2022

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

Add support for using arrow keys in the QuestionHelper.

There was already a try #36700 to fix the issue.

The approach here does not depend on readline at all (removed in #17669)

For now it's an RFC. I'm free for other ideas and criticism on this approach.

For now in this PR are supported these key combinations:

Key combination Comment
Backward one character
CTRL + B Backward one character
Forward one character
CTRL + F Forward one character
CTRL + Backward one word
ALT + B Backward one word
CTRL + SHIFT + Backward one word
CTRL + Forward one word
ALT + F Forward one word
CTRL + SHIFT + Forward one word
CTRL + H Delete previous character
Backspace Delete previous character
Delete Delete next character
CTRL + A Beginning of input
Home Beginning of input
CTRL + E End of input
End End of input

Feel free to test it out and leave comments about the experience.

For better testing i now created a repo https://github.com/maxbeckers/symfony-cli-input-handling

@maxbeckers maxbeckers requested a review from chalasr as a code owner Nov 22, 2022
@carsonbot carsonbot added Status: Needs Review Status: Needs Work Console DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Nov 22, 2022
@carsonbot carsonbot added this to the 6.2 milestone Nov 22, 2022
@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.2" but it seems your PR description refers to branch "6.3".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [WIP][RFC][DX][Console] Support left and right arrow for QuestionHelper [Console] [WIP] Support left and right arrow for QuestionHelper Nov 22, 2022
@fabpot fabpot modified the milestones: 6.2, 6.3 Nov 23, 2022
@maxbeckers maxbeckers force-pushed the patch-36657 branch 3 times, most recently from 6d3e73c to 51b434d Compare Nov 24, 2022
@maxbeckers maxbeckers changed the title [Console] [WIP] Support left and right arrow for QuestionHelper [Console] Support left and right arrow for QuestionHelper Nov 24, 2022
@maxbeckers
Copy link
Contributor Author

maxbeckers commented Nov 24, 2022

Now I have a stand that needs to be reviewed.

I add a zip for easier testing. Feel free to test and try it and find all the bugs.
test-48287.zip

The solution might not be perfect, but for me it seems to work fine. Only with ESC the solution has it's problems. Maybe someone has for that an idea. ESC is "\033" and ctrl buttons as well start with this char.

Current Test failures seem not to be related to the PR.

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

This is a great improvement for user experience in interactive commands.

I understand that is a proof-of-concept. There is other key and key combination to get the same experience than the shell.

  • Key HOME and END (same as Ctrl+A and Ctrl+E)
  • Key Alt+Right Arrow and Alt+Left Arrow move from word to word (I just discovered that the behavior is not the same on bash or zsh, the - is a word-breaker on bash, not on zsh)

https://stackoverflow.com/questions/5029118/bash-ctrl-to-move-cursor-between-words-strings

src/Symfony/Component/Console/Helper/QuestionHelper.php Outdated Show resolved Hide resolved
@maxbeckers
Copy link
Contributor Author

@GromNaN thanks for your input. Yes, you're right, it's a proof of concept. Because of that i ask for comments on this approach. Now there is a solid base and i need feedback to optimize it.

I'll have a look to the other key combinations you mentioned.

@maxbeckers maxbeckers changed the title [Console] Support left and right arrow for QuestionHelper [Console] Support a set of control keys and key combinations in QuestionHelper Nov 25, 2022
@maxbeckers
Copy link
Contributor Author

Added the mentioned:

  • Key HOME and END
  • move from word to word

Test zip: test-48287-2.zip

@maxbeckers
Copy link
Contributor Author

maxbeckers commented Nov 26, 2022

One problem for now is with a question in a output section with SymfonyStyle ... I'll try to find a solution for that.

UPDATE found a solution for the section input. not very nice, maybe someone has a good idea here. I create a new ConsoleOutput because the input for the question in section in handled after the section with the stdin/stdout.
test-48287.zip

@maxbeckers maxbeckers force-pushed the patch-36657 branch 2 times, most recently from 015ba6d to 0d1cbd1 Compare Nov 28, 2022
@Chi-teck
Copy link
Contributor

I think the keys should match default readline configuration.
https://github.com/chzyer/readline/blob/v1.5.1/doc/shortcut.md

Though we might not need to cover all readline features.

@maxbeckers
Copy link
Contributor Author

hi @Chi-teck and thanks for the link. I'll have a look to that the next days in detail. But i guess some of the keys are already implemented the way readline has implemented it as well. But of course we'll only have a set of this keys.

@maxbeckers
Copy link
Contributor Author

maxbeckers commented Jan 23, 2023

Hi @Chi-teck,

I updated the description of this PR including all of the currently supported key combinations. It matches the keys of readline and has just some bash additions added.

I of course only added key combinations making sense to the question helper input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Console DX DX = Developer eXperience (anything that improves the experience of using Symfony) Feature RFC RFC = Request For Comments (proposals about features that you want to be discussed) Status: Needs Review Status: Needs Work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Console: Support Left/Right Arrow Keys
5 participants