1use dialogos::*;
2
3fn play(d: &mut Dialogue) {
4 while !d.has_end() {
5 if d.has_menu() {
6 let choices = d.choices();
7 println!("\nEnter a number:");
9 for (i, text) in choices.iter().enumerate() {
10 println!("{} => {}", i + 1, text);
11 }
12 loop {
14 let mut input = String::new();
15 std::io::stdin().read_line(&mut input).expect("Oops error!");
16 if let Ok(choice) = input.trim().parse::<usize>() {
17 if choice > 0 && choice <= choices.len() {
18 d.choose(choice - 1);
19 break;
20 }
21 }
22 }
23 println!();
24 }
25 let line = d.line();
26 println!("{}: {}", line.info, line.cont);
27 d.next();
28 }
29}
30
31fn main() {
32 let gigi = |cont| text("Gigi", cont);
33
34 let mut d = Dialogue::new(vec![
35 gigi("What should I do?"),
36 menu("Coffee||Tea||Sleep", "Drink coffee.||Drink tea.||Go sleep."),
37 label("Coffee"),
38 gigi("I drink the coffee."),
39 end(),
40 label("Tea"),
41 gigi("I drink the tea."),
42 end(),
43 label("Sleep"),
44 gigi("I drink the sleep."),
45 ]);
46 play(&mut d);
47}