Warning
This post was published 59 days ago. The information described in this article may have changed.
This is a clone from my StackOverflow post. https://stackoverflow.com/questions/79707263/is-it-possible-to-host-a-repl-child-process-in-rustyline
I'm currently working on a rustyline
program. My goal is to host another REPL program as a child process, and do something like auto complete its commands. However, I encountered a problem. The readline()
function in rustyline::Editor
would block, and if the child process wants to print something after the readline()
call, it would not be shown before the user press enter to unblock it. This really destroys user experiences. Here's some code for clearer understanding.
loop {
// rx is a receiver handled by the thread that runs the child process
while let Ok(output_line) = rx.try_recv() {
println!("{}", output_line);
}
let readline = rl.readline("> "); // This will block until user press enter
match readline { // Code that do with readline
...
}
Spawning a thread that prints the child process's output continuously doesn't work, either. We can't know when to readline and display the >
prompt.
1 post - 1 participant
🏷️ rust_feed