Struct dialoguer::Confirm

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

Renders a confirm prompt.

§Example

use dialoguer::Confirm;

fn main() {
    let confirmation = Confirm::new()
        .with_prompt("Do you want to continue?")
        .interact()
        .unwrap();

    if confirmation {
        println!("Looks like you want to continue");
    } else {
        println!("nevermind then :(");
    }
}

Implementations§

source§

impl Confirm<'static>

source

pub fn new() -> Self

Creates a confirm prompt with default theme.

source§

impl Confirm<'_>

source

pub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self

Sets the confirm prompt.

source

pub fn report(self, val: bool) -> Self

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

The default is to report the chosen selection.

source

pub fn wait_for_newline(self, wait: bool) -> Self

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.

source

pub fn default(self, val: bool) -> Self

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.

source

pub fn show_default(self, val: bool) -> Self

Disables or enables the default value display.

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

source

pub fn interact(self) -> Result<bool>

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’.

source

pub fn interact_opt(self) -> Result<Option<bool>>

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’.

§Example
use dialoguer::Confirm;

fn main() {
    let confirmation = Confirm::new()
        .interact_opt()
        .unwrap();

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

pub fn interact_on(self, term: &Term) -> Result<bool>

Like interact but allows a specific terminal to be set.

source

pub fn interact_on_opt(self, term: &Term) -> Result<Option<bool>>

Like interact_opt but allows a specific terminal to be set.

source§

impl<'a> Confirm<'a>

source

pub fn with_theme(theme: &'a dyn Theme) -> Self

Creates a confirm prompt with a specific theme.

§Example
use dialoguer::{theme::ColorfulTheme, Confirm};

fn main() {
    let confirmation = Confirm::with_theme(&ColorfulTheme::default())
        .interact()
        .unwrap();
}

Trait Implementations§

source§

impl<'a> Clone for Confirm<'a>

source§

fn clone(&self) -> Confirm<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Confirm<'static>

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a> Freeze for Confirm<'a>

§

impl<'a> !RefUnwindSafe for Confirm<'a>

§

impl<'a> !Send for Confirm<'a>

§

impl<'a> !Sync for Confirm<'a>

§

impl<'a> Unpin for Confirm<'a>

§

impl<'a> !UnwindSafe for Confirm<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.