pub struct Confirm<'a> { /* private fields */ }Expand description
Builder for a yes/no confirmation prompt.
Wraps Terminal::confirm with a chainable configuration API. Call
Confirm::ask to display the prompt and block until the user answers.
§Example
use vecli::Confirm;
let confirmed = Confirm::new("Delete file?")
.default(false)
.ask();Implementations§
Source§impl<'a> Confirm<'a>
impl<'a> Confirm<'a>
Sourcepub fn new(prompt: &'a str) -> Self
pub fn new(prompt: &'a str) -> Self
Creates a new Confirm with the given question text.
Defaults to false when the user presses Enter, with the default indicator visible.
Examples found in repository?
examples/taskr.rs (line 127)
121fn clear(ctx: &CommandContext) {
122 // Demonstrates: Confirm prompt, global flag
123 if ctx.flags.contains_key("verbose") {
124 println!("[verbose] clear called.");
125 }
126
127 let confirmed = Confirm::new("Clear all tasks?").default(false).ask();
128
129 if confirmed {
130 println!("All tasks cleared.");
131 } else {
132 println!("Aborted.");
133 }
134}Sourcepub fn default(self, default: bool) -> Self
pub fn default(self, default: bool) -> Self
Sets the value returned when the user presses Enter with no input.
Examples found in repository?
examples/taskr.rs (line 127)
121fn clear(ctx: &CommandContext) {
122 // Demonstrates: Confirm prompt, global flag
123 if ctx.flags.contains_key("verbose") {
124 println!("[verbose] clear called.");
125 }
126
127 let confirmed = Confirm::new("Clear all tasks?").default(false).ask();
128
129 if confirmed {
130 println!("All tasks cleared.");
131 } else {
132 println!("Aborted.");
133 }
134}Sourcepub fn show_default(self, show: bool) -> Self
pub fn show_default(self, show: bool) -> Self
Controls whether [Y/n] or [y/N] is appended to the prompt text.
Sourcepub fn ask(self) -> bool
pub fn ask(self) -> bool
Displays the prompt and returns the user’s answer.
Examples found in repository?
examples/taskr.rs (line 127)
121fn clear(ctx: &CommandContext) {
122 // Demonstrates: Confirm prompt, global flag
123 if ctx.flags.contains_key("verbose") {
124 println!("[verbose] clear called.");
125 }
126
127 let confirmed = Confirm::new("Clear all tasks?").default(false).ask();
128
129 if confirmed {
130 println!("All tasks cleared.");
131 } else {
132 println!("Aborted.");
133 }
134}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> UnsafeUnpin 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
Mutably borrows from an owned value. Read more