kkawakam / rustyline

Readline Implementation in Rust
https://crates.io/crates/rustyline/
MIT License
1.5k stars 173 forks source link

Feature request: Julia-style "next command" down key in the REPL #781

Open ageron opened 1 week ago

ageron commented 1 week ago

Julia's REPL has a really nice feature: when you press the \<down> key and you just picked and executed command #N in the history, then the REPL will select command #N+1 in the history (assuming you haven't pressed \<up> yet).

For example:

julia> 1+1
2
julia> 2+2
4
julia> 3+3
6
julia> 4+4
8
julia> 2+2        #<-- this command was selected in the history by typing <up><up><up>
4
julia> 3+3        #<-- this command was selected simply by typing <down> (instead of <up><up><up>)
6
julia> 4+4        #<-- this command was also selected simply by typing <down> (instead of <up><up><up>)
8

Rationale: it's very common to execute several commands in a row from the history (perhaps skipping or editing a few of them). If these commands are far up in the history, then it's cumbersome to have to go back up for each one of them. Thanks to this "next command" feature, you only need to go back up for the command #N, then for every subsequent command, you just press once (or several times if you want to skip some commands).

It's probably not very hard to implement, and it's a real pleasure to use (git it a try!). Plus it won't break any user's expectations since this scenario currently does nothing at all.

gwenn commented 1 week ago

The history_index is lost/reset each time you press enter / validate the line.

If we keep this history_index state, we must ensure that it is invalidated if History is cleared / reloaded / ...

gwenn commented 1 week ago