Macro fyi_msg::confirm

source ·
macro_rules! confirm {
    (yes: $text:expr) => { ... };
    (yes: $text:expr, $indent:expr) => { ... };
    (no: $text:expr) => { ... };
    (no: $text:expr, $indent:expr) => { ... };
    ($text:expr) => { ... };
    ($text:expr, $indent:expr) => { ... };
}
Expand description

§Confirm.

This is a convenience macro for generating a confirmation message, handling the prompting, and returning the response bool.

§Example

use fyi_msg::{confirm, Msg, MsgKind};

// The manual way:
if Msg::new(MsgKind::Confirm, "Do you like chickens?").prompt() {
    println!("That's great! They like you too!");
}

// The macro way:
if confirm!("Do you like chickens?") {
    println!("That's great! They like you too!");
}

// If you want to default to yes, prefix thusly:
if confirm!(yes: "Do you like chickens?") {
    println!("That's great! They like you too!");
}

// Indentation can be set with the macro too by appending a second
// argument:
if confirm!("Do you like chickens?", 1) {
    println!("    That's great! They like you too!");
}

// The "yes:" prefix also works here.
if confirm!(yes: "Do you like chickens?", 1) {
    println!("    That's great! They like you too!");
}