-
Notifications
You must be signed in to change notification settings - Fork 178
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
Add an async interface #126
Comments
I was thinking about tokio support, which basically means async support. I'm probably also trying to sketch something up. |
https://docs.rs/tokio/0.1/tokio/io/struct.Stdin.html
|
For what it's worth, I think that this could be accomplished with a wrapper type on the current editor. I don't think Rustyline internals need to change to read from stdin asynchronously, I think it just needs to provide an async-compatible interface, which should probably be a futures Stream of As @Marwes mentioned, this would probably be most easily accomplished by spawning a thread and running a standard Rustyline |
@RadicalZephyr I don't know how to make sure |
That's a good question. I'm not super familiar with trying to do this so this might be a naive suggestion, but I think that the most straightforward solution would be to enforce that the thread running the rustyline editor is the only one allowed to write to stdout. I'll try to put together an example as a proof of concept and at least initial guidance on how to use rustyline in an async context. |
I've just pushed #200 a basic start on using rustyline from an async context. The current strategy I'm using would only be able to show lines sent to the display from an async context after the user finishes editing the current line and before the next line becomes available to edit. I think for async use to be really nice, it would be good to have a new interface that allows output to be sent while the user is editing a line. I'm thinking of being able to create a remote "handle" to an |
Very excited to see this receiving attention!
One reason to build async support into rustyline would be to allow operation without threads in cases where that is possible (e.g. stdin/out connected to a terminal or pipe on *nix). That's a lot of complexity for dubious benefit, though.
Something like this sounds really great! Producing output without interfering with a prompt is exactly what I want for building e.g. an admin interface to a server. You might be able to get away with a synchronous |
It'd also be nice to be able to use async for output from the log crate; a stretch-goal-feature for this could be a wrapper for Handle that impls |
If anyone still wants to add this feature to rustyline, I've made a cleanroom implementation that could be used as a reference. |
Are you planning to add this in the future? |
I am not sure but removing / replacing ExternalPrinter by the clever / simple linenoise solution is appealing. |
I spent a few hours looking into this, and implementing an incremental read API similar to linenoise would be a significant architectural shift. This isn't simply a matter of moving the needed state into the right place (currently the state is spread out across Basically we'd need to keep a stack of I think this approach is the right one as it would make it trivial to use rustyline in async, multi-threaded, and single-threaded multiplex ( |
Probably needs to spawn an OS thread and perform all line reading there with a channel (I don't think there is another way to do it anyway). I could (an likely will) implement this outside
rustyline
but if it seems useful enough to warrant inclusion I am happy to do a PR.https://github.com/alexcrichton/futures-rs
The text was updated successfully, but these errors were encountered: