Crates.io | ask |
lib.rs | ask |
version | 0.0.11 |
source | src |
created_at | 2018-10-24 22:02:20.45133 |
updated_at | 2019-12-12 18:47:31.972548 |
description | A toolset for nicely displayed Questions and Answers through the terminal. |
homepage | |
repository | https://gitlab.com/Omega-Tree/ask-rs |
max_upload_size | |
id | 92494 |
size | 44,207 |
A simple toolset for asking questions through the terminal.
extern crate ask;
use ask::question::{MultipleChoice, OptionGroup, TraitQuestion, QuestionOption};
use ask::validate;
fn main() {
let mut multiple_choice = MultipleChoice::new("What would you like to order?".to_owned());
let answer_collections = multiple_choice
.add_option_group(
OptionGroup::new("Entrees")
.add_option_by_str("Calamari".to_owned())
.add_option_by_str("Buffalo wings".to_owned())
.add_option_by_str("Shrimp".to_owned())
)
.add_option_group(
OptionGroup::new("Main Course")
.add_option(QuestionOption::new("Lobster".to_owned()))
.add_option(QuestionOption::new("T-Bone".to_owned()).toggle_selected(None))//toggle the selected to opposite to what it currently is
.add_option(QuestionOption::new("Burger".to_owned()).toggle_selected(Some(false)))
.add_option(QuestionOption::new("Duck".to_owned()).toggle_selected(Some(true))) //set this option to be selected by default asking the question
)
.set_validation(Box::new(|answer_collection| {
validate::group_options::selections_are_gtoe(& answer_collection, 1) &&
validate::group_options::selections_are_ltoe(& answer_collection, 1)
})
)
// .replace_continue_btn("CAN CONTINUE!!".to_owned(), "CANNOT CONTINUE!!".to_owned()) //can customize continue btn
.send()
.unwrap();
println!("");
// let answer_collections = multiple_choice.to_answer_collections(); //can pull the answer_collections at any time
for answer_sets in answer_collections.answer_sets{
for answer in answer_sets.answers{
println!("{}", answer);
}
}
should show: