-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
151 additions
and
217 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,20 @@ | ||
//! This module implements a confirmation prompt. | ||
//! Confirmation prompt. | ||
use std::{ | ||
io, | ||
io::{BufRead, Write}, | ||
}; | ||
use common::maestro_utils; | ||
|
||
/// Asks for confirmation. If yes, true is returned. Else, false is returned. | ||
pub fn prompt() -> bool { | ||
let mut first = true; | ||
let stdin = io::stdin(); | ||
let mut response; | ||
|
||
loop { | ||
if first { | ||
print!("Confirm? [y/n] "); | ||
} else { | ||
print!("Please type `y` or `n`. "); | ||
} | ||
|
||
let _ = io::stdout().flush(); | ||
|
||
// Waiting for an input line | ||
let input = stdin.lock().lines().next().unwrap().unwrap(); | ||
response = input == "y"; | ||
|
||
// If the input is correct, stop asking | ||
if input == "y" || input == "n" { | ||
break; | ||
let Some(input) = maestro_utils::prompt::prompt(Some("Confirm? [Y/n] "), false) else { | ||
// Input closed, abort | ||
break false; | ||
}; | ||
let input = input.trim().to_lowercase(); | ||
match input.as_str() { | ||
"" | "y" | "ye" | "yes" => break true, | ||
"n" | "no" => break false, | ||
// Retry | ||
_ => {} | ||
} | ||
|
||
first = false; | ||
} | ||
|
||
println!(); | ||
|
||
response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.