Environment:
- macOS 11.6.8
- Terminal.app (
TERM=xterm-256color
)
- Rust 1.65.0
- rustyline-async commit f9817e7 cloned from GitHub
When running the readline
example in this repository, if I hit Ctrl-D, the program exits immediately without printing the "Exiting..." message, like so:
If I remove the break
in the Err(ReadlineError::Eof)
branch, the message is printed.
Similarly, if I add a break
to the Err(ReadlineError::Interrupted)
branch, pressing Ctrl-C results in the "^C" message not being printed — along with an additional prompt being printed before my shell command prompt, like so:
Adding rl.flush()?;
or Write::flush(&mut stdout)?;
after the call to writeln
doesn't help.
Note that this isn't just limited to Eof
and Interrupted
, either. When running the following code:
use rustyline_async::{Readline, ReadlineError};
use std::io::Write;
use std::time::Duration;
use tokio::time::sleep;
#[tokio::main]
async fn main() -> Result<(), ReadlineError> {
let (mut rl, mut stdout) = Readline::new("> ".into())?;
loop {
tokio::select! {
_ = sleep(Duration::from_secs(3)) => {
writeln!(stdout, "Message received!")?;
}
cmd = rl.readline() => match cmd {
Ok(line) => {
writeln!(stdout, "{line:?}")?;
rl.add_history_entry(line.clone());
if line == "quit" {
break;
}
}
Err(ReadlineError::Eof) => {
writeln!(stdout, "<EOF>")?;
break;
}
Err(ReadlineError::Interrupted) => {
writeln!(stdout, "<Ctrl-C>")?;
break;
}
Err(e) => {
writeln!(stdout, "Error: {e:?}")?;
break;
}
}
}
}
Ok(())
}
typing "quit" will result in the program exiting without outputting "quit"
, yet it still outputs the next readline prompt (which ends up prepended to my shell prompt), like so: