mikaelmello / inquire

A Rust library for building interactive prompts
https://docs.rs/inquire
MIT License
1.71k stars 72 forks source link

Added 'History' support, along with default SimpleHistory implementation and tests #229

Open mikecvet opened 3 months ago

mikecvet commented 3 months ago

This is a suggested implementation of prompt history for Text proposed in https://github.com/mikaelmello/inquire/issues/224

The diff hooks into the key bindings for up and down arrows, currently used for suggestion navigation, to also potentially navigate upwards and downwards through prompt history.

A user can set a prompt history when creating their new Text via something liek

    let input = Text::new(&terminal_prompt)
      .with_history(SimpleHistory::new(history_string_vec.clone()))
      .prompt();
mikaelmello commented 3 months ago

I think this is pretty great, thanks a lot for the contributions!

The diff hooks into the key bindings for up and down arrows, currently used for suggestion navigation, to also potentially navigate upwards and downwards through prompt history.

This made me think of an approach that I believe would work really well, let me know your thoughts:

On a fundamental level, this is another approach on giving suggestions to the user. Think about normal bash "up and down" vs fzf which displays a list to be selected.

Also, the current suggestion approach (a selection list) obviously conflicts with this in terms of keybindings, which leads me to think they are exclusive to each other.

I feel that inquire is reaching a stage where it's bloated with a ton of different pieces to use but it's missing a better UX story. I think there is a path here for a unified approach to suggestions/auto-completion/history

mikecvet commented 3 months ago

I think this is pretty great, thanks a lot for the contributions!

Thanks!

On a fundamental level, this is another approach on giving suggestions to the user. Think about normal bash "up and down" vs fzf which displays a list to be selected.

Yes, agreed.

Also, the current suggestion approach (a selection list) obviously conflicts with this in terms of keybindings, which leads me to think they are exclusive to each other.

I feel that inquire is reaching a stage where it's bloated with a ton of different pieces to use but it's missing a better UX story. I think there is a path here for a unified approach to suggestions/auto-completion/history

Yeah, while building this feature, and largely pairing it with autocomplete side-by-side, it seemed like supporting a generalized "navigation" framework, which can hook into suggestions, history, or whatever else, would be the right way to go. I'd love to be able to define some kind of callback or handler for specific keystrokes within my application, and feed outputs back into the prompt

Baarsgaard commented 3 months ago

I've been pondering over something like a "Query" prompt similar to what you're both describing. My notes which I haven't finished thinking through: