blob: 8691c2e4e79938c0d6b9f28d8659f3ca3153c872 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
use dialoguer::{theme::ColorfulTheme, Input};
fn main() {
let input: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Your name")
.interact_text()
.unwrap();
println!("Hello {}!", input);
let mail: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Your email")
.validate_with({
let mut force = None;
move |input: &String| -> Result<(), &str> {
if input.contains('@') || force.as_ref().map_or(false, |old| old == input) {
Ok(())
} else {
force = Some(input.clone());
Err("This is not a mail address; type the same value again to force use")
}
}
})
.interact_text()
.unwrap();
println!("Email: {}", mail);
let mail: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Your planet")
.default("Earth".to_string())
.interact_text()
.unwrap();
println!("Planet: {}", mail);
let mail: String = Input::with_theme(&ColorfulTheme::default())
.with_prompt("Your galaxy")
.with_initial_text("Milky Way".to_string())
.interact_text()
.unwrap();
println!("Galaxy: {}", mail);
}
|