From 84bfea7add93a98f83ad958151cca718c33bc0a4 Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Fri, 11 Jan 2019 02:31:29 +0000 Subject: 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. --- src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 80cabb5..da89e2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { if let Ok(backend) = env::var("DIALOG") { @@ -363,5 +367,9 @@ pub fn default_backend() -> Box { } } - Box::new(backends::Dialog::new()) + if backends::Dialog::is_available() { + Box::new(backends::Dialog::new()) + } else { + Box::new(backends::Stdio::new()) + } } -- cgit v1.2.1