pub struct Dialog<'a> {
pub title: String,
pub theme: &'a Theme,
pub description: String,
pub buttons: Vec<DialogButton>,
/* private fields */
}Expand description
A dialog to display to the user
§Example
use demand::Dialog;
use demand::DialogButton;
let dialog = Dialog::new("Are you sure?")
.description("This will do a thing.")
.buttons(vec![
DialogButton::new("Ok"),
DialogButton::new("Not sure"),
DialogButton::new("Cancel"),
]);
let choice = match dialog.run() {
Ok(value) => value,
Err(e) => {
if (e.kind() == std::io::ErrorKind::Interrupted) {
println!("Dialog cancelled");
return;
} else {
panic!("Error: {}", e);
}
}
};Fields§
§title: StringThe title of the selector
theme: &'a ThemeThe colors/style of the selector
description: StringA description to display above the selector
The buttons to display to the user
Implementations§
Source§impl<'a> Dialog<'a>
impl<'a> Dialog<'a>
Sourcepub fn new<S: Into<String>>(title: S) -> Self
pub fn new<S: Into<String>>(title: S) -> Self
Create a new dialog with the given title
By default, the dialog will have a single “Ok” button and a “Cancel” button.
Sourcepub fn description(self, description: &str) -> Self
pub fn description(self, description: &str) -> Self
Set the description of the dialog
Set the buttons of the dialog
Set the index of the initially selected button.
The idx is the index of the button in the buttons vector and is 0-indexed.
§Errors
This will panic if there are no buttons to select or if the index is out of bounds.
Sourcepub fn run(self) -> Result<String>
pub fn run(self) -> Result<String>
Displays the dialog to the user and returns their response.
The response will be the label of the selected button.
This function will block until the user submits the input. If the user cancels the input,
an error of type io::ErrorKind::Interrupted is returned.
Auto Trait Implementations§
impl<'a> Freeze for Dialog<'a>
impl<'a> RefUnwindSafe for Dialog<'a>
impl<'a> Send for Dialog<'a>
impl<'a> Sync for Dialog<'a>
impl<'a> Unpin for Dialog<'a>
impl<'a> UnwindSafe for Dialog<'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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more