Crate dialog

source ·
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:

These dialog boxes can be displayed using various backends:

  • Dialog: uses dialog to display ncurses-based dialog boxes (requires the external dialog tool)
  • [Stdio][]: prints messages to the standard output and reads user input form standard input (intended as a fallback backend)
  • [Zenity][]: uses zenity to display GTK-based dialog boxes (requires the external zenity 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 that display dialog boxes.

Structs

A dialog box with a text input field.
A message box.
A dialog box with a password input field.
A question dialog box.

Enums

A user choise in a dialog box.
An error returned by dialog.

Traits

A dialog box that can be shown using a backend.

Functions

Creates a new instance of the default backend.

Type Definitions

A result returned by dialog.