dialog_box/
lib.rs

1/**
2 * Copyright (c) 2019 Pankaj Chaudhary
3 *
4 * This source code is licensed under the MIT License found in
5 * the LICENSE file in the root directory of this source tree.
6 */
7use std::process::Command;
8
9/// The calender function can give the dialog-box/popup on the screen by which we can put the desired output as per our requirement. This function can return the input value.
10pub fn calender(title: &str) -> String {
11    match Command::new("zenity")
12        .args(&["--calendar", "--text=Pick a day" , "--title", title])
13        .output() {
14            Ok(success) => String::from_utf8(success.stdout).unwrap(),
15            Err(error) => error.to_string(),
16    }
17}
18
19/// The information function can display the dialog-box/popup on the screen with the given argument.
20pub fn information(info: &str ) -> String {
21    match Command::new("zenity")
22        .args(&["--info", "--text", info])
23        .output() {
24        Ok(_success) => "Information displayed.".to_string(),
25        Err(error) => error.to_string(),
26    }
27}
28
29/// The question function can give the dialog-box/popup on the screen by which we can put the desired answer for that question. This function can return the answer.
30pub fn question(question: &str ) -> String {
31    match Command::new("zenity")
32        .args(&["--entry", "--text", question])
33        .output() {
34        Ok(success) => String::from_utf8(success.stdout).unwrap(),
35        Err(error) => error.to_string(),
36    }
37}
38
39/// The progress function can display the progress dialog-box/popup on the screen.
40pub fn progress() -> String {
41    match Command::new("zenity")
42        .args(&["--progress", "--pulsate"])
43        .output() {
44        Ok(_success) => "Process complete.".to_string(),
45        Err(error) => error.to_string(),
46    }
47}
48
49/// The error function can display the error dialog-box/popup on the screen with the given error message.
50pub fn error(error_message: &str) -> String {
51    match Command::new("zenity")
52        .args(&["--error", "--text", error_message])
53        .output() {
54        Ok(_success) => "Error displayed.".to_string(),
55        Err(error) => error.to_string(),
56    }
57}
58
59/// The warning function can display the warning dialog-box/popup on the screen with the given warning message.
60pub fn warning(message: &str) -> String {
61    match Command::new("zenity")
62        .args(&["--warning", "--text", message])
63        .output() {
64        Ok(_success) => "Warning displayed.".to_string(),
65        Err(error) => error.to_string(),
66    }
67}
68
69/// The file_path function can give the dialog-box/popup on the screen by which we can path of our directory. This function can return the entered path of directory.
70pub fn file_path() -> String {
71    match Command::new("zenity")
72        .args(&["--file-selection"])
73        .output() {
74        Ok(success) => String::from_utf8(success.stdout).unwrap(),
75        Err(error) => error.to_string(),
76    }
77}
78
79/// The pick_number function can give the dialog-box/popup on the screen by which we can choose any number between 1 to 100. This function can return that number.
80pub fn pick_number(title: &str) -> String {
81    match Command::new("zenity")
82        .args(&["--scale", "--text", title])
83        .output() {
84        Ok(success) => String::from_utf8(success.stdout).unwrap(),
85        Err(error) => error.to_string(),
86    }
87}