diff options
author | Robin Krahl <robin.krahl@ireas.org> | 2019-01-11 02:31:29 +0000 |
---|---|---|
committer | Robin Krahl <robin.krahl@ireas.org> | 2019-01-11 03:32:45 +0100 |
commit | 84bfea7add93a98f83ad958151cca718c33bc0a4 (patch) | |
tree | cd860c19962398c06b17f383931441787a6e786e /src/lib.rs | |
parent | dc754cbc9763b3ea6979ed55bd4e8030fe073078 (diff) | |
download | dialog-rs-84bfea7add93a98f83ad958151cca718c33bc0a4.tar.gz dialog-rs-84bfea7add93a98f83ad958151cca718c33bc0a4.tar.bz2 |
Add the stdio backend
This patch adds the stdio backend which acts as a fallback backend and
uses standard input and output. For password queries, the rpassword
crate is used to suppress output. Also, default_backend is changed to
return Stdio if Dialog is not available.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -15,6 +15,8 @@ //! 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) //! @@ -344,9 +346,11 @@ impl DialogBox for Question { /// - If the `DISPLAY` environment variable is set, the first available backend from this list is /// used: /// - [`Zenity`][] -/// - Otherwise, a [`Dialog`][] instance is returned. +/// - If the [`Dialog`][] backend is available, it is used. +/// - Otherwise, a [`Stdio`][] instance is returned. /// /// [`Dialog`]: backends/struct.Dialog.html +/// [`Stdio`]: backends/struct.Stdio.html /// [`Zenity`]: backends/struct.Zenity.html pub fn default_backend() -> Box<dyn backends::Backend> { if let Ok(backend) = env::var("DIALOG") { @@ -363,5 +367,9 @@ pub fn default_backend() -> Box<dyn backends::Backend> { } } - Box::new(backends::Dialog::new()) + if backends::Dialog::is_available() { + Box::new(backends::Dialog::new()) + } else { + Box::new(backends::Stdio::new()) + } } |