1mod dialog;
5mod kdialog;
6mod stdio;
7mod zenity;
8
9pub use crate::backends::dialog::Dialog;
10pub use crate::backends::kdialog::KDialog;
11pub use crate::backends::stdio::Stdio;
12pub use crate::backends::zenity::Zenity;
13
14use std::env;
15use std::path;
16
17use crate::Result;
18
19pub trait Backend {
29 fn show_input(&self, input: &super::Input) -> Result<Option<String>>;
31
32 fn show_message(&self, message: &super::Message) -> Result<()>;
34
35 fn show_password(&self, password: &super::Password) -> Result<Option<String>>;
37
38 fn show_question(&self, question: &super::Question) -> Result<super::Choice>;
40
41 fn show_file_selection(&self, file_selection: &super::FileSelection) -> Result<Option<String>>;
43}
44
45pub(crate) fn is_available(name: &str) -> bool {
46 if let Ok(path) = env::var("PATH") {
47 for part in path.split(':') {
48 if path::Path::new(part).join(name).exists() {
49 return true;
50 }
51 }
52 }
53 false
54}
55
56pub(crate) fn from_str(s: &str) -> Option<Box<dyn Backend>> {
57 match s.to_lowercase().as_ref() {
58 "dialog" => Some(Box::new(Dialog::new())),
59 "kdialog" => Some(Box::new(KDialog::new())),
60 "stdio" => Some(Box::new(Stdio::new())),
61 "zenity" => Some(Box::new(Zenity::new())),
62 _ => None,
63 }
64}