Macro termimad::ask[][src]

macro_rules! ask {
    ($skin : expr, $question : expr,
 { $(($key : expr, $answer : expr) => $r : block) + }) => { ... };
    ($skin : expr, $question : expr, ($default_answer : expr)
 { $(($key : expr, $answer : expr) => $r : block) + }) => { ... };
}
Expand description

ask the user to choose among proposed answers.

This macro makes it possible to propose several choices, with an optional default ones, to execute blocks, to optionaly return a value.

Example:

use termimad::*;

let skin = get_default_skin();

let beverage = ask!(skin, "What do I serve you ?", {
    ('b', "**B**eer") => {
        ask!(skin, "Really ? We have wine and orange juice too", (2) {
            ("oj", "**o**range **j**uice") => { "orange juice" }
            ('w' , "ok for some wine") => { "wine" }
            ('b' , "I said **beer**") => { "beer" }
            ( 2  , "Make it **2** beer glasses!") => { "beer x 2" }
        })
    }
    ('w', "**W**ine") => {
        println!("An excellent choice!");
        "wine"
    }
});

Limits compared to the Question API:

  • the default answer, if any, must be among the declared ones

Note that examples/ask contains several examples of this macro.