rustyline-async
rustyline-async copied to clipboard
is there a way to do autocomplete with suggestions?
is this supported by this library?
Nope, but if you have an autocompletion engine in mind, I don't think that would be too difficult to integrate.
All that would be required is to have some module provide a function that takes the content of a line and returns a list of autocompletions.
fn autocomplete(line: &str, autocompletions: &mut Vec<String>, requested: u32) {
// Take line and write the requested number of completions with requested number
}
Once you have that, a naive display of potential autocompletes could be done, or possibly something more complicated where the user can scroll through them.
Actually creating an autocompletion engine though is probably a bit beyond the scope of this project, although I'm curious what the rustyline crate does :thinking:.
I'm not actively using this library anymore so I probably won't implement new features myself, but I'll definitely review and merge PRs!
Would be really awesome to have the ability to register async completion handlers, e.g. to perform a web request that fetches completion candidates. This is the feature I have been missing in the other readline crates.
That does sound pretty awesome ngl! I'm not coding for this project atm, but I will review and merge pretty much anything so long as it isn't really badly designed :).
From my first guess, this doesn't seem like it'd be too big of a change (the crate already uses async for everything). You'd just have to implement the completion TUI and then allow users to handle completion requests from the readline and satisfy completion requests. If I was implementing it, it might go something like:
Edit line.rs character event (or if you want completion on tab use the relevant crossterm event) to generate a new ReadlineEvent (i.e. like ReadlineEvent::SearchCompletion). and implement a new function that renders a locally stored "completion_list: Vec<String>" on the Readline. The rendering might be the trickiest part.
If you manage to do that though, then you could handle that event directly in the main event loop (i.e. where you handle all the other ReadlineEvents) and provide a helper function on Readline to update the current suggestion... Or if you wanted a more seamless experience with async completion handlers you could handle the SearchCompletion event in the readline() event loop in lib.rs, making it task::spawn a preregistered async fn with the current line string, the JoinHandle of which could be stored in the readline and awaited in the select! loop, updating the suggestion TUI in the LineState struct on completion.