Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle EOF in user input prompts #1293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pacman doesn't print anything for this. In fact it doesn't even print a new line.

Paru tries to match pacman when possible so negative on EOF is good but I don't think we should print anything but a new line. Otherwise it kind of messes up the input. I'll see about changing pacman to be like that too.

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
}
}
}

Expand Down