-
Notifications
You must be signed in to change notification settings - Fork 9
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
How should history work? #5
Comments
Just giving my thoughts on some of these aspects again :) About the changeability:
About the storage:
About the functionality:
|
Yeah, I suppose all those other fun features can be a future project. I guess have a tendency to over-engineer things : ) About the Mutexs, I am trying to keep the library runtime agnostic so using a mutex from tokio or async-std is a no-go, it is better to just use futures::channels instead and receive from a Edit: Does futures::lock use spinlocks?, in general, I tend to avoid mutexs because you can create deadlocks... |
Okay, I re-implemented your history using channels, with some ability to extend for prefix-based searching like how it works in zsh (i.e. you type |
Issue on implementation details for readline history:
Up for debate
Mutex
to ensure thread-safety of appending new entries.Failing to acquire a lock (which should only be possible, if another thread panicked with the lock), will currently panic.
Alternatives:
RwLock
instead, currently not really useful as there aren't really any read-only accesses.Readline
Readline
?VecDeque
used is currently created through default.Technically a capacity could be specified based on the
max_size
.This could consume unnecessarily large memory amounts when the
max_size
is high, but the history's actual length is low.My Thoughts
Probably... A history is a history because it happened in the past, and past in unchangeable.
Nahh
My "perfect" history implementation would look something along the lines of :
a. The downside sync-to-file is how its done, do we use
Seek
to look for newlines between history entries? Or do we manually serialize & deserialize the whole file whenever we want to sync? seeking & appending would be faster, but what happens if we want max history sizes? then the whole file needs to be rewritten which may require loading the entire thing into memory.Definitely, maybe even its own library to allow for other people to use it.
That is a good idea, and is basically what rustyline does, which goes with the theme of trying to match their api.
Also to consider: do we want to have history searching (which would probably necessitate a BTree of some kind) or history deduplication?
This is how rustyline does it, no async tho: https://docs.rs/rustyline/6.3.0/src/rustyline/history.rs.html#25-30
I'm curious how
ion
does it, but I cannot grok their codebase...The text was updated successfully, but these errors were encountered: