pub struct Confirm<'a> { /* private fields */ }
Expand description

Renders a confirm prompt.

Example usage

use dialoguer::Confirm;

if Confirm::new().with_prompt("Do you want to continue?").interact()? {
    println!("Looks like you want to continue");
} else {
    println!("nevermind then :(");
}

Implementations

Creates a confirm prompt.

Sets the confirm prompt.

Indicates whether or not to report the chosen selection after interaction.

The default is to report the chosen selection.

👎 Deprecated since 0.6.0:

Use with_prompt() instead

Sets when to react to user input.

When false (default), we check on each user keystroke immediately as it is typed. Valid inputs can be one of ‘y’, ‘n’, or a newline to accept the default.

When true, the user must type their choice and hit the Enter key before proceeding. Valid inputs can be “yes”, “no”, “y”, “n”, or an empty string to accept the default.

Sets a default.

Out of the box the prompt does not have a default and will continue to display until the user inputs something and hits enter. If a default is set the user can instead accept the default with enter.

Disables or enables the default value display.

The default is to append the default value to the prompt to tell the user.

Enables user interaction and returns the result.

The dialog is rendered on stderr.

Result contains bool if user answered “yes” or “no” or default (configured in default if pushes enter. This unlike interact_opt does not allow to quit with ‘Esc’ or ‘q’.

Enables user interaction and returns the result.

The dialog is rendered on stderr.

Result contains Some(bool) if user answered “yes” or “no” or Some(default) (configured in default) if pushes enter, or None if user cancelled with ‘Esc’ or ‘q’.

Like interact but allows a specific terminal to be set.

Examples
use dialoguer::Confirm;
use console::Term;

let proceed = Confirm::new()
    .with_prompt("Do you wish to continue?")
    .interact_on(&Term::stderr())?;

Like interact_opt but allows a specific terminal to be set.

Examples
use dialoguer::Confirm;
use console::Term;

fn main() -> std::io::Result<()> {
    let confirmation = Confirm::new()
        .interact_on_opt(&Term::stdout())?;

    match confirmation {
        Some(answer) => println!("User answered {}", if answer { "yes" } else { "no " }),
        None => println!("User did not answer")
    }

    Ok(())
}

Creates a confirm prompt with a specific theme.

Examples
use dialoguer::{
    Confirm,
    theme::ColorfulTheme
};

let proceed = Confirm::with_theme(&ColorfulTheme::default())
    .with_prompt("Do you wish to continue?")
    .interact()?;

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.