-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
repl: add reverse search #31006
repl: add reverse search #31006
Conversation
This adds support for very long input lines to still display the input preview correct.
385ef1a
to
c7ecd5d
Compare
Add a reverse search that works similar to the ZSH one. It is triggered with <ctrl> + r and <ctrl> + s. It skips duplicated history entries and works with multiline statements. Matching entries indicate the search parameter with an underscore and cancelling with <ctrl> + c or escape brings back the original line. Multiple matches in a single history entry work as well and are matched in the order of the current search direction. The cursor is positioned at the current match position of the history entry. Changing the direction immediately searches checks for the next entry in the expected direction from the current position on. Entries are accepted as soon any button is pressed that doesn't correspond with the reverse search. The behavior is deactivated for simple terminals. They do not support most ANSI escape codes that are necessary for this feature.
This just removes some redundant work and some other small things.
The cursor move functions accept a callback. It was possible that `undefined` was returned in case there was no error instead of null.
c7ecd5d
to
7f38f0a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
||
const alreadyMatched = new Set(); | ||
const labels = { | ||
r: 'bck-i-search: ', |
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.
Can these prompts be less abbreviated?
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.
Do you have a suggestion? I thought it's nice to keep it aligned with ZSH and to also keep the length of both strings identical. backward-i-search
and forward-i-search
has a one character length difference.
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.
Is it OK to land this as is? We can also change the name later on in a patch.
This appears to work as advertised. 👍 |
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.
Left a few nits and I'm not sure we should support this - but code wise this is good enough to land IMO :]
I just addressed the nits, fixed one very unlikely issue (search lines exceeding the current terminal columns) and added a big TODO entry. Resizing the terminal will hide the overlay and fixing that requires significant work inside of readline. This should definitely not be a blocker though. @benjamingr in what way are you uncertain that we should support reverse-i-search? It is one of my biggest missed features :D (I also plan on adding more features soonish). |
This comment has been minimized.
This comment has been minimized.
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.
changes lgtm
documentation update checkbox is checked, but no doc files have been updated I don't think? |
This comment has been minimized.
This comment has been minimized.
Notable changes: * assert: * Implement `assert.match()` and `assert.doesNotMatch()` (Ruben Bridgewater) #30929 * events: * Add `EventEmitter.on` to async iterate over events (Matteo Collina) #27994 * Allow monitoring error events (Gerhard Stoebich) #30932 * fs: * Allow overriding `fs` for streams (Robert Nagy) #29083 * perf_hooks: * Move `perf_hooks` out of experimental (legendecas) #31101 * repl: * Implement ZSH-like reverse-i-search (Ruben Bridgewater) #31006 * tls: * Add PSK (pre-shared key) support (Denys Otrishko) #23188 PR-URL: #31238
Notable changes: * assert: * Implement `assert.match()` and `assert.doesNotMatch()` (Ruben Bridgewater) #30929 * events: * Add `EventEmitter.on` to async iterate over events (Matteo Collina) #27994 * Allow monitoring error events (Gerhard Stoebich) #30932 * fs: * Allow overriding `fs` for streams (Robert Nagy) #29083 * perf_hooks: * Move `perf_hooks` out of experimental (legendecas) #31101 * repl: * Implement ZSH-like reverse-i-search (Ruben Bridgewater) #31006 * tls: * Add PSK (pre-shared key) support (Denys Otrishko) #23188 PR-URL: #31238
Notable changes: * assert: * Implement `assert.match()` and `assert.doesNotMatch()` (Ruben Bridgewater) #30929 * events: * Add `EventEmitter.on` to async iterate over events (Matteo Collina) #27994 * Allow monitoring error events (Gerhard Stoebich) #30932 * fs: * Allow overriding `fs` for streams (Robert Nagy) #29083 * perf_hooks: * Move `perf_hooks` out of experimental (legendecas) #31101 * repl: * Implement ZSH-like reverse-i-search (Ruben Bridgewater) #31006 * tls: * Add PSK (pre-shared key) support (Denys Otrishko) #23188 PR-URL: #31238
This adds support for very long input lines to still display the input preview correct. PR-URL: nodejs#31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Add a reverse search that works similar to the ZSH one. It is triggered with <ctrl> + r and <ctrl> + s. It skips duplicated history entries and works with multiline statements. Matching entries indicate the search parameter with an underscore and cancelling with <ctrl> + c or escape brings back the original line. Multiple matches in a single history entry work as well and are matched in the order of the current search direction. The cursor is positioned at the current match position of the history entry. Changing the direction immediately checks for the next entry in the expected direction from the current position on. Entries are accepted as soon any button is pressed that doesn't correspond with the reverse search. The behavior is deactivated for simple terminals. They do not support most ANSI escape codes that are necessary for this feature. PR-URL: nodejs#31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This just removes some redundant work and some other small things. PR-URL: nodejs#31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
The cursor move functions accept a callback. It was possible that `undefined` was returned in case there was no error instead of null. PR-URL: nodejs#31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This adds support for very long input lines to still display the input preview correct. PR-URL: #31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Add a reverse search that works similar to the ZSH one. It is triggered with <ctrl> + r and <ctrl> + s. It skips duplicated history entries and works with multiline statements. Matching entries indicate the search parameter with an underscore and cancelling with <ctrl> + c or escape brings back the original line. Multiple matches in a single history entry work as well and are matched in the order of the current search direction. The cursor is positioned at the current match position of the history entry. Changing the direction immediately checks for the next entry in the expected direction from the current position on. Entries are accepted as soon any button is pressed that doesn't correspond with the reverse search. The behavior is deactivated for simple terminals. They do not support most ANSI escape codes that are necessary for this feature. PR-URL: #31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This just removes some redundant work and some other small things. PR-URL: #31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
The cursor move functions accept a callback. It was possible that `undefined` was returned in case there was no error instead of null. PR-URL: #31006 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This adds a reverse search similar to zsh. Please check the commit messages for details.
This is still WIP. It needs tests and one line length issue must be fixed.Update: done
See it in action: https://asciinema.org/a/shV3YOFu74BcBakJcvY4USNqv
Supersedes #24335
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes