From 5448a473cad35d35ab6ae9cb2fd6da660086a857 Mon Sep 17 00:00:00 2001 From: Daniel Ploch Date: Mon, 22 Jan 2024 11:51:57 -0500 Subject: [PATCH] ui: handle EOF on prompts --- cli/src/ui.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cli/src/ui.rs b/cli/src/ui.rs index 9cffad161..b2d338b9d 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -340,6 +340,16 @@ impl Ui { self.stdout().flush()?; let mut buf = String::new(); 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) }