aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-11 01:54:49 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-01-11 02:56:32 +0100
commitdc754cbc9763b3ea6979ed55bd4e8030fe073078 (patch)
treea9ea62a8486450861883fa2d9e2362c594a3f1b4 /src/lib.rs
parent02190c44f7072b4fdaca50836a583f955866f8de (diff)
downloaddialog-rs-dc754cbc9763b3ea6979ed55bd4e8030fe073078.tar.gz
dialog-rs-dc754cbc9763b3ea6979ed55bd4e8030fe073078.tar.bz2
Check DISPLAY environment variable in default_backend
This patch changes the default_backend to also check the DISPLAY environment variable. If it is set, there probably is a X server running, so we try to use the zenity backend. Otherwise, the dialog backend is used.
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3a6a090..80cabb5 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -341,9 +341,13 @@ impl DialogBox for Question {
/// - If the `DIALOG` environment variable is set to a valid backend name, this backend is used.
/// A valid backend name is the name of a struct in the `backends` module implementing the
/// `Backend` trait in any case.
+/// - If the `DISPLAY` environment variable is set, the first available backend from this list is
+/// used:
+/// - [`Zenity`][]
/// - Otherwise, a [`Dialog`][] instance is returned.
///
/// [`Dialog`]: backends/struct.Dialog.html
+/// [`Zenity`]: backends/struct.Zenity.html
pub fn default_backend() -> Box<dyn backends::Backend> {
if let Ok(backend) = env::var("DIALOG") {
if let Some(backend) = backends::from_str(&backend) {
@@ -351,5 +355,13 @@ pub fn default_backend() -> Box<dyn backends::Backend> {
}
}
+ if let Ok(display) = env::var("DISPLAY") {
+ if !display.is_empty() {
+ if backends::Zenity::is_available() {
+ return Box::new(backends::Zenity::new());
+ }
+ }
+ }
+
Box::new(backends::Dialog::new())
}