Expand description
Displays dialog boxes using various backends.
The dialog
crate can be used to display different types of dialog boxes. The supported types
are:
FileSelection
: a file chooser dialog boxInput
: a text input dialogMessage
: a simple message boxPassword
: a password input dialogQuestion
: a question dialog box
These dialog boxes can be displayed using various backends:
Dialog
: usesdialog
to display ncurses-based dialog boxes (requires the externaldialog
tool)KDialog
: useskdialog
to display Qt-based dialog boxes (requires the externalkdialog
tool)Stdio
: prints messages to the standard output and reads user input form standard input (intended as a fallback backend)Zenity
: useszenity
to display GTK-based dialog boxes (requires the externalzenity
tool)
You can let dialog
choose the backend by calling the show
method on a dialog box. If
you want to choose the backend yourself, create a backend instance and pass it to
show_with
. You can also use the default_backend
function to create a backend.
§Examples
Show a message box using the default backend:
use dialog::DialogBox;
dialog::Message::new("Did you know that I am using the dialog crate?")
.title("Public Service Announcement")
.show()
.expect("Could not display dialog box");
Show a message box using the Dialog
backend with customized settings:
use dialog::DialogBox;
let mut backend = dialog::backends::Dialog::new();
backend.set_backtitle("dialog demo");
backend.set_width(100);
backend.set_height(10);
dialog::Message::new("Did you know that I am using the dialog crate?")
.title("Public Service Announcement")
.show_with(&backend)
.expect("Could not display dialog box");
Query a string from the user:
use dialog::DialogBox;
let name = dialog::Input::new("Please enter your name")
.title("Name")
.show()
.expect("Could not display dialog box");
match name {
Some(name) => println!("Hello {}!", name),
None => println!("Hello stranger!"),
};
Modules§
- backends
- Backends that display dialog boxes.
Structs§
- File
Selection - A file chooser dialog box.
- Input
- A dialog box with a text input field.
- Message
- A message box.
- Password
- A dialog box with a password input field.
- Question
- A question dialog box.
Enums§
- Choice
- A user choise in a dialog box.
- Error
- An error returned by
dialog
. - File
Selection Mode - The type of a file selection dialog.
Traits§
- Dialog
Box - A dialog box that can be shown using a backend.
Functions§
- default_
backend - Creates a new instance of the default backend.
Type Aliases§
- Result
- A result returned by
dialog
.