From fb5f72cff0a258590f2e35fc1c40eaff79962014 Mon Sep 17 00:00:00 2001 From: Roman Stingler Date: Wed, 25 Dec 2024 01:39:48 +0100 Subject: [PATCH] fix: handle EOF in user input prompts - Add proper EOF detection in ask() function - Print " -> EOF" message when EOF is received - Treat EOF as negative response - Handle input read errors explicitly closes #1190 --- src/util.rs | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/util.rs b/src/util.rs index d66f5889..d9e7eae5 100644 --- a/src/util.rs +++ b/src/util.rs @@ -134,16 +134,27 @@ pub fn ask(config: &Config, question: &str, default: bool) -> bool { } let stdin = stdin(); let mut input = String::new(); - let _ = stdin.read_line(&mut input); - let input = input.to_lowercase(); - let input = input.trim(); - - if input == tr!("y") || input == tr!("yes") { - true - } else if input.trim().is_empty() { - default - } else { - false + match stdin.read_line(&mut input) { + Ok(0) => { + println!(" -> EOF"); + false + } + Ok(_) => { + let input = input.to_lowercase(); + let input = input.trim(); + + if input == tr!("y") || input == tr!("yes") { + true + } else if input.trim().is_empty() { + default + } else { + false + } + } + Err(_) => { + println!(" -> Error reading input"); + false + } } }