-
Notifications
You must be signed in to change notification settings - Fork 93
Add key bindings for PgUp and PgDn #509
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
|
@ima1zumi here is the MR to handle PgUp and PgDn, which we talked about in #434 and decided to pull it out into a separate MR. Rather than provide the same functionality as up/down arrow keys, I'm still leaning towards just making them be ignored, but I'm also open to having them provide a different, but still useful functionality (that is still related to history). For example, I found these lines in my /etc/inputrc, which makes me believe there are others who see usefulness in mapping PgUp/PgDn to something else that is still history-related, but not the same thing as up/down arrow keys: (It looks like reline doesn't support beginning_of_history and end_of_history yet, but it does support history_search_backward and history_search_forward.) Interestingly, I tested a bunch of shells and none of them support PgUp/PgDn out of the box. Of course, that doesn't necessarily mean reline shouldn't support them by default. Here's what different shells do:
I believe the shells that print out So we have most shells really just don't handle these at all, and only one or two do handle them, but only to make them ignored. So I don't think it is a bad decision to have reline ignore them. At least it's a step up from allowing the escape codes to get spewed out. (I don't think anyone gets pleasure from that). So maybe shells are either just really old and never bothered to support PgUp/PgDn, or there was never a general consensus on what they should do, so they've decided to leave it up to people to choose the desired behavior by modifying their inputrc. So here are some choices we have for PgUp/PgDn in reline:
Given there are no shells that enable behavior by default, I think the best course of action would be for reline also to not provide a default behavior, but rather left it up to individuals to introduce a behavior (which they can do by modifying their inputrc). However, leaving the code as is and just allowing the escape codes to get printed out is distracting to say the least, so I think it is a step up and good to at least ignore them by default, like But I am open to discussion and am willing to do 3 or 4 if there is a good argument for doing so. Of those two I would lean towards 4 just so people don't get in the habit of thinking pgup/pgdn should behave the same way as |
|
@ima1zumi, have you had a chance to look at this? |
|
I think this pull request is related to #514 |
Hi @tompng . Yep, this PR handles PgUp and PgDn, and it does so in the correct and best way possible, using capname key bindings that utilizes your terminfo, so they will get ignored regardless of what escape sequence your terminal sends for them. Another key we can handle this way is the Insert key, by mapping the We can also handle all the function keys this way, by mapping I think we're both after the same thing here, but maybe your thinking about it a different way and thinking we should try to fix a bunch of keys at once in one PR. I'm not opposed to that, but I already tried fixing four keys in one PR (delete key, pgup, pgdn, and insert), by handling delete properly and by ignoring the other three, but not only did it take 10 months to get that approved, and I had to go out of my way to add unit tests for ansi.rb that never had unit tests before, but I was also asked to remove everything except the handling of the delete key and create separate PRs for other keys. So that is why I am now taking it slow and only fixing one or two keys at a time; also, this allows for a discussion about exactly how the keys should be handled, and with PgUp and PgDn especially, it's not necessarily true that we want to ignore them; we could also very well choose to map them to specific useful actions instead. I am waiting for @ima1zumi to weigh in on how we want to handle these two keys. |
ima1zumi
left a comment
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.
Thanks for the report. I propose another idea.
lib/reline/ansi.rb
Outdated
| 'kpp' => :ed_ignore, | ||
| 'knp' => :ed_ignore, |
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.
It would be better to make it behave the same as IRB using Readline.
| 'kpp' => :ed_ignore, | |
| 'knp' => :ed_ignore, | |
| 'kpp' => :ed_prev_history, | |
| 'knp' => :ed_next_history, |
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.
Oh, I didn't even think about checking to see what IRB does when using Readline instead of Reline.
@ima1zumi can you tell me how to test IRB with Readline? Do I just run irb --nomultiline?
Because I tried that and PgUp and PgDn did not behave that way. PgUp got ignored and PgDn turned into a ~.
What is your OS and version of libreadline? I'm running Debian Linux 11 and have libreadline version 8.1-1.
Also, out of curiosity what shell are you using and how does it behave?
I think you are only seeing this behavior because of your specific setup. I think maybe your readline has been specifically configured to handle them. Can you check your ~/.inputrc and /etc/inputrc? Can you test again after temporarily removing those files or anything else that could be influencing readline?
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.
@sshock I also observed what @ima1zumi described because that's a new behaviour added to readline 8.2 (changelog). Quote:
d. Automatically bind termcap key sequences for page-up and page-down to
history-search-backward and history-search-forward, respectively.
I appreciate that you tested readline with IRB yourself and shared your findings. However, it'd be great if you don't make quick assumptions on other people's setup follow by a series of questions. I know the intention was good but it could be seen as a bit aggressive and could make others uncomfortable.
Also, a quick way to share setup info is to paste the output of the irb_info command:
For example,
irb(main):001:0> irb_info
Ruby version: 3.2.1
IRB version: irb 1.6.3 (2023-03-06)
InputMethod: RelineInputMethod with Reline 0.3.2
RUBY_PLATFORM: arm64-darwin22
LANG env: en_US.UTF-8
East Asian Ambiguous Width: 1
With ~/.inputrb
irb(main):001:0> irb_info
Ruby version: 3.2.1
IRB version: irb 1.6.3 (2023-03-06)
InputMethod: RelineInputMethod with Reline 0.3.2 and /Users/hung-wulo/.inputrc
RUBY_PLATFORM: arm64-darwin22
LANG env: en_US.UTF-8
East Asian Ambiguous Width: 1
With readline
irb(main):001:0> irb_info
Ruby version: 3.2.1
IRB version: irb 1.6.3 (2023-03-06)
InputMethod: ReadlineInputMethod with ext/readline 8.2
RUBY_PLATFORM: arm64-darwin22
LANG env: en_US.UTF-8
East Asian Ambiguous Width: 1
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.
@sshock I also observed what @ima1zumi described because that's a new behaviour added to
readline 8.2(changelog). Quote:d. Automatically bind termcap key sequences for page-up and page-down to
history-search-backward and history-search-forward, respectively.
Oh, neat!
I appreciate that you tested readline with IRB yourself and shared your findings. However, it'd be great if you don't make quick assumptions on other people's setup follow by a series of questions. I know the intention was good but it could be seen as a bit aggressive and could make others uncomfortable.
Very sorry. My system was up-to-date, so it never occurred to me that I might have an old libreadline, and even if I did think of that I never would have imagined that they would begin to provide default behavior for these keys after so many years of not really handling them.
I will try to be more careful in the future and not jump to conclusions.
Also, a quick way to share setup info is to paste the output of the
irb_infocommand:
This is very useful, thanks!
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.
@sshock I also observed what @ima1zumi described because that's a new behaviour added to
readline 8.2(changelog). Quote:d. Automatically bind termcap key sequences for page-up and page-down to
history-search-backward and history-search-forward, respectively.
Good news. I was able to test on a newer system with readline 8.2 and confirm that pgup/pgdn using IRB w/ readline does indeed have history-search-backward and history-search-forward behavior as described in the changelog.
I will update the PR shortly. I am in 100% in agreement with making reline match the behavior of readline by default.
In the latest readline (8.2), page-up and page-down are bound to history-search-backward and history-search-forward by default. We would like reline to have the same default behavior.
|
@st0012 @ima1zumi ready for re-review 🙏 Let's get this in! I would like to clear up one point of confusion.
So I've used Keep in mind that |
Thank you! I agree with you. |
|
👍 |
(ruby/reline#509) * Add key bindings for PgUp, PgDn * Match behavior of readline 8.2 In the latest readline (8.2), page-up and page-down are bound to history-search-backward and history-search-forward by default. We would like reline to have the same default behavior.
This adds default key bindings for PgUp and PgDn so that instead of spewing out ugly escape codes they will
just be ignoredprovide history-search-backward and history-search-forward behavior (just like the latest readline 8.2).Helps with issue ruby/irb#330.