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

More flexible history save/load #127

Closed
netvl opened this issue Dec 22, 2017 · 6 comments · Fixed by #604
Closed

More flexible history save/load #127

netvl opened this issue Dec 22, 2017 · 6 comments · Fixed by #604

Comments

@netvl
Copy link

netvl commented Dec 22, 2017

I would like to be able to save user input history to and load it from a database. However, the current load/save API requires using a file. It is kind of possible to load/save history in line-by-line fashion, but this is suboptimal - there is no method on History to access the underlying VecDeque, and there is also no way to fill it with lines without using add() which performs the history addition logic.

One possible solution I see would be to implement the following pair of methods:

pub fn replace_entries<I, S>(&mut self, lines: I) where I: IntoIter<Item=S>, S: Into<String> {}
pub fn entries(&self) -> impl Iterator<Item=&str> {}

I can do this, but will the PR be merged? I see that the repo is not very active.

@gwenn
Copy link
Collaborator

gwenn commented Mar 2, 2018 via email

@netvl
Copy link
Author

netvl commented Mar 5, 2018

@gwenn I have taken a look at the libraries you listed and found the following:

  1. Haskeline has methods to access the entire history as a list of strings, but it appears not to have bulk add features, and in general is also heavily file-centered.
  2. Liner is heavily file-centered and has no API to manage history manually.
  3. Linefeed does not seem to have history saving features. It allows reading the entire history, but no bulk add is possible.
  4. Linenoise only has file-based API.
  5. Ditto for linenoise-ng.
  6. jline3 has a generic History interface which can be implemented by storing and loading history in any arbitrary way, though the default implementation is for files.

This is kinda surprising for me; making history management modular is such an obvious thing to me, I don't understand why it is not supported by almost all readline-like libraries out there.

@gwenn
Copy link
Collaborator

gwenn commented Mar 5, 2018

Ok,
What about a Backend trait to persist (load and save) the history entries ?
Make Path (or AsRef<Path>) implements Backend.
And fix History.save/load by passing a &Backend.

Or an History trait.
And make current implementation the default.

@luser
Copy link

luser commented Oct 3, 2018

I've long wanted a more flexible history solution for my shell. I currently use a bunch of hacks to share history between different open bash shells, forcing them to save and load history between each command. This mostly works, but the biggest downside is that the ordering of commands in each shell is not preserved, so up arrow sometimes produces counter-intuitive results because it will return the last command executed in any shell.

It would be nice to have something that could make this work nicely--a history that's shared among multiple running programs, but where each program has its own linear set of history entries.

gwenn added a commit to gwenn/rustyline that referenced this issue Feb 23, 2022
Fix kkawakam#127
Fix kkawakam#442

TODO
- [ ] check if `History::add` and `History::add_owned` can be fused
- [ ] put old / default `FileHistory` behind a feature
- [ ] SQLite based implementation behind a feature
- [ ] timestamped history ? Implementation detail ?
- [ ] editable entry ? later ?

Breaking changes:
* `Editor` impacted (new generic type parameter `I`)
* `History` renamed to `FileHistory`
* History API impacted (to make trait object safe)
@gwenn gwenn mentioned this issue Feb 23, 2022
5 tasks
@gwenn
Copy link
Collaborator

gwenn commented Feb 23, 2022

4 years later => #604
Feedback is welcome.

@gwenn
Copy link
Collaborator

gwenn commented Feb 19, 2023

5 years later => version 11.0.0 released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants