forked from mirrors/jj
ui: handle EOF on prompts
This commit is contained in:
parent
ad05a8750a
commit
5448a473ca
1 changed files with 10 additions and 0 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue