-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
survey_minimal.rs
88 lines (76 loc) · 3.08 KB
/
survey_minimal.rs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use promptuity::prompts::{
Confirm, Input, MultiSelect, MultiSelectOption, Number, Password, Select, SelectOption,
};
use promptuity::themes::MinimalTheme;
use promptuity::{Error, Promptuity, Term};
fn main() -> Result<(), Error> {
let mut term = Term::default();
let mut theme = MinimalTheme::default();
let mut p = Promptuity::new(&mut term, &mut theme);
p.term().clear()?;
p.begin()?;
let name = p.prompt(Input::new("Please enter your username").with_placeholder("username"))?;
let years = p.prompt(
Number::new("How many years of software development experience do you have?")
.with_min(0)
.with_max(120),
)?;
let full =
p.prompt(Confirm::new("Are you a full-time software developer?").with_default(true))?;
let language = p.prompt(
Select::new(
"Select your primary programming language",
vec![
SelectOption::new("Rust", "rust"),
SelectOption::new("Go", "go"),
SelectOption::new("C++", "cpp"),
SelectOption::new("C", "c"),
SelectOption::new("TypeScript", "typescript"),
SelectOption::new("JavaScript", "javascript"),
SelectOption::new("Deno", "deno"),
SelectOption::new("Python", "python"),
SelectOption::new("Java", "java"),
SelectOption::new("Dart", "dart"),
SelectOption::new("Other", "other"),
],
)
.as_mut(),
)?;
let interests = p.prompt(
MultiSelect::new(
"Select the fields you are interested in",
vec![
MultiSelectOption::new("Web Development", "web"),
MultiSelectOption::new("Mobile App Development", "app"),
MultiSelectOption::new("Data Science", "ds"),
MultiSelectOption::new("Cloud Computing", "cloud"),
MultiSelectOption::new("Database Management", "db"),
MultiSelectOption::new("Devices and IoT", "iot"),
MultiSelectOption::new("AI and Machine Learning", "ml"),
MultiSelectOption::new("Game Development", "game"),
MultiSelectOption::new("Security", "security"),
MultiSelectOption::new("Frontend Development", "frontend"),
MultiSelectOption::new("Backend Development", "backend"),
MultiSelectOption::new("Open Source Projects", "oss"),
],
)
.with_hint("Multiple selections allowed"),
)?;
let password = p.prompt(
Password::new("Set a password for your account").with_validator(|value: &String| {
if value.len() < 6 {
Err("Password must be at least 6 characters long".into())
} else {
Ok(())
}
}),
)?;
p.finish()?;
println!("name: {name:?}");
println!("years: {years:?}");
println!("full: {full:?}");
println!("language: {language:?}");
println!("interests: {interests:?}");
println!("password: {password:?}");
Ok(())
}