Skip to content
Merged
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
34 changes: 28 additions & 6 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,20 @@ pub fn prompt_microstructure_variable(connection: &mut PgConnection) -> Option<c
let mut input = String::new();

// Read user input
io::stdin()
.read_line(&mut input)
.expect("Failed to read input");
loop {
input.clear();
let bytes = io::stdin()
.read_line(&mut input)
.expect("Failed to read input");

if bytes == 0 {
return None; // EOF
}

if !input.trim().is_empty() {
break;
}
}

// Check if input is "1)" or "1"
let trimmed = input.trim();
Expand Down Expand Up @@ -52,9 +63,20 @@ pub fn prompt_cutoff_value() -> Option<f32> {
let mut input = String::new();

// Read user input
io::stdin()
.read_line(&mut input)
.expect("Failed to read input");
loop {
input.clear();
let bytes = io::stdin()
.read_line(&mut input)
.expect("Failed to read input");

if bytes == 0 {
return None; // EOF
}

if !input.trim().is_empty() {
break;
}
}

// The user can only enter a number for now, anything else will exit the function.
if let Ok(divide) = input.trim().parse::<f32>() {
Expand Down
Loading