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<'_>
impl Confirm<'_>
sourcepub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self
pub fn with_prompt<S: Into<String>>(self, prompt: S) -> Self
Sets the confirm prompt.
sourcepub fn report(self, val: bool) -> Self
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.
sourcepub fn wait_for_newline(self, wait: bool) -> Self
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.
sourcepub fn default(self, val: bool) -> Self
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.
sourcepub fn show_default(self, val: bool) -> Self
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.
sourcepub fn interact(self) -> Result<bool>
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’.
sourcepub fn interact_opt(self) -> Result<Option<bool>>
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")
}
}
sourcepub fn interact_on(self, term: &Term) -> Result<bool>
pub fn interact_on(self, term: &Term) -> Result<bool>
Like interact
but allows a specific terminal to be set.
sourcepub fn interact_on_opt(self, term: &Term) -> Result<Option<bool>>
pub fn interact_on_opt(self, term: &Term) -> Result<Option<bool>>
Like interact_opt
but allows a specific terminal to be set.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)