multiple_choice_food_menu/
multiple_choice_food_menu.rs

1extern crate ask;
2
3use ask::question::{MultipleChoice, OptionGroup, TraitQuestion, QuestionOption};
4use ask::validate;
5
6fn main() {
7    // let mut ask = ask::Ask::new();
8    // ask.question(OpenEnded::new( "question?".to_string()));
9    // ask.all();
10
11    // let mut open_ended = OpenEnded::new("question?".to_string());
12    // let answers = open_ended.send();
13
14    let mut multiple_choice = MultipleChoice::new("What would you like to order?".to_owned());
15
16    let answer_collections = multiple_choice
17        .add_option_group(
18            OptionGroup::new("Entrees")
19                .add_option_by_str("Calamari".to_owned())
20                .add_option_by_str("Buffalo wings".to_owned())
21                .add_option_by_str("Shrimp".to_owned())
22        )
23        .add_option_group(
24            OptionGroup::new("Main Course")
25                .add_option(QuestionOption::new("Lobster".to_owned()))
26                .add_option(QuestionOption::new("T-Bone".to_owned()).toggle_selected(None))//toggle the selected to opposite to what it currently is
27                .add_option(QuestionOption::new("Burger".to_owned()).toggle_selected(Some(false)))
28                .add_option(QuestionOption::new("Duck".to_owned()).toggle_selected(Some(true))) //set this option to be selected by default asking the question
29        )
30        .set_validation(Box::new(|answer_collection| {
31                validate::group_options::selections_are_gtoe(& answer_collection, 0) &&
32                validate::group_options::selections_are_ltoe(& answer_collection, 3)
33            })
34        )
35        // .replace_continue_btn("CAN CONTINUE!!".to_owned(), "CANNOT CONTINUE!!".to_owned()) //can customize continue btn
36        .send()
37        .unwrap();
38
39
40    println!("");
41
42    // let answer_collections = multiple_choice.to_answer_collections(); //can pull the answer_collections at any time
43    for answer_sets in answer_collections.answer_sets{
44        for answer in answer_sets.answers{
45            println!("{}", answer);
46        }
47    }
48}