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

is there a way to do autocomplete with suggestions? #15

Open
Kreijstal opened this issue Aug 23, 2023 · 3 comments
Open

is there a way to do autocomplete with suggestions? #15

Kreijstal opened this issue Aug 23, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@Kreijstal
Copy link

is this supported by this library?

@zyansheep
Copy link
Owner

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 🤔.

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!

@zyansheep zyansheep added the enhancement New feature or request label Dec 1, 2023
@fwcd
Copy link

fwcd commented Mar 18, 2024

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.

@zyansheep
Copy link
Owner

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" 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants