Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/Tools/langtool/src/util.rs
5654 views
1
use std::io::{self, Write};
2
3
#[allow(dead_code)]
4
pub fn ask_yes_no(question: &str) -> bool {
5
loop {
6
println!("{} (y/n): ", question);
7
8
let mut input = String::new();
9
io::stdin()
10
.read_line(&mut input)
11
.expect("Failed to read line");
12
13
match input.trim().to_lowercase().as_str() {
14
"y" | "yes" => return true,
15
"n" | "no" => return false,
16
_ => println!("Please enter 'y' or 'n'"),
17
}
18
}
19
}
20
21
pub fn ask_letter(question: &str, allowed_chars: &str) -> char {
22
loop {
23
println!("{question} ({allowed_chars}): ");
24
let _ = io::stdout().flush();
25
26
let mut input = String::new();
27
io::stdin()
28
.read_line(&mut input)
29
.expect("Failed to read line");
30
31
match input
32
.trim()
33
.to_lowercase()
34
.as_str()
35
.chars()
36
.next()
37
{
38
Some(c) => {
39
if allowed_chars.contains(c) {
40
return c;
41
}
42
}
43
_ => println!("Please enter a character"),
44
}
45
}
46
}
47
48