ok/jj
1
0
Fork 0
forked from mirrors/jj

ui: handle EOF on prompts

This commit is contained in:
Daniel Ploch 2024-01-22 11:51:57 -05:00 committed by Daniel Ploch
parent ad05a8750a
commit 5448a473ca

View file

@ -340,6 +340,16 @@ impl Ui {
self.stdout().flush()?; self.stdout().flush()?;
let mut buf = String::new(); let mut buf = String::new();
io::stdin().read_line(&mut buf)?; io::stdin().read_line(&mut buf)?;
if let Some(trimmed) = buf.strip_suffix('\n') {
buf = trimmed.to_owned();
} else if buf.is_empty() {
return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"Prompt cancelled by EOF",
));
}
Ok(buf) Ok(buf)
} }