Skip to main content

basic/
basic.rs

1//! The crate's normal usage in one small program: check that a
2//! backend exists, ask for text, and ask a yes/no question,
3//! handling a cancel at each step as the `None` it is rather
4//! than as an error.
5//!
6//! Run it with `cargo run --example basic` on a machine with a
7//! desktop session. For the file dialogs, including filters,
8//! see the `open_with_filters` example.
9
10use any_dialog::Dialogs;
11
12fn main() -> Result<(), any_dialog::Error> {
13    let dialogs = Dialogs::new();
14    if !dialogs.available() {
15        eprintln!("no dialog backend on this system (on Linux, install kdialog or zenity)");
16        return Ok(());
17    }
18
19    let Some(name) = dialogs.prompt_text("any-dialog basic example", "Your name:", None)? else {
20        println!("cancelled at the name prompt");
21        return Ok(());
22    };
23    println!("hello, {name}");
24
25    if dialogs.confirm("any-dialog basic example", "Show an info message?")? {
26        dialogs.show_info("any-dialog basic example", "That was a confirm.")?;
27    } else {
28        println!("no message wanted; done");
29    }
30    Ok(())
31}