Implement prompt_int function for integer input

Add a function to prompt for an integer input with validation.
This commit is contained in:
S.B
2026-02-13 00:48:03 +02:00
committed by GitHub
parent a1ca9c3e43
commit 4049849a53
+10
View File
@@ -112,6 +112,16 @@ pub fn prompt_yes_no(msg: &str, default_yes: bool) -> Result<bool> {
}
}
pub fn prompt_int(msg: &str, default: i64) -> Result<i64> {
loop {
let input = prompt_default(msg, &default.to_string())?;
match input.trim().parse::<i64>() {
Ok(n) => return Ok(n),
Err(_) => println!("{}", "Please enter a valid number.".yellow()),
}
}
}
pub fn prompt_int_range(msg: &str, default: i64, min: i64, max: i64) -> Result<i64> {
loop {
let input = prompt_default(msg, &default.to_string())?;