Skip to content

Commit 20e1995

Browse files
authored
22 allow skip input validation (#30)
* removed re-export * removed print if invalid arguments * removed unsued code * reworked input Added: - Multiple Requirements - valid and Invalid Notes - additional notes for shotcuts - default option - support for ALLow_COLOR * update input example to work with the new input struct * fixed text not removing after condition match * update preview image * added documentation
1 parent d99c59a commit 20e1995

5 files changed

Lines changed: 431 additions & 237 deletions

File tree

examples/input.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
use regex::Regex;
2-
use zenity::menu::input::{valid_path, valid_regex};
2+
3+
use zenity::menu::input::{Input, Requirements};
34

45
fn main() {
5-
println!("Input Preview:");
6+
println!("\n\nInput Preview:");
7+
8+
let path = Input::new("Enter Valid Path:", Requirements::default()).start();
9+
let path_with_regex = Input::new(
10+
"Enter a Valid .toml file",
11+
Requirements::path()
12+
.set_regex(Regex::new(r"\.toml\z").unwrap())
13+
.set_note("", "Please Enter a Valid Path to a .toml file"),
14+
)
15+
.start();
16+
let regex = Input::new(
17+
"Enter Valid Regex (ABC):",
18+
Requirements::regex(Regex::new(r"^ABC$").unwrap()),
19+
)
20+
.allow_force()
21+
.set_default("ABC")
22+
.start();
623

7-
println!(
8-
"\n\nReturn: {}",
9-
valid_regex(
10-
"Enter string:",
11-
Regex::new(r"^\d{3}$").unwrap(),
12-
Some("369"),
13-
false
14-
)
15-
);
16-
println!(
17-
"\n\nPath: {:?}",
18-
valid_path("Enter A Valid Path:", None, true)
19-
);
24+
println!("Existing Path: {:?}", path);
25+
println!("Path with Regex: {:?}", path_with_regex);
26+
println!("Regex: {:?}", regex);
2027
}

images/rustrover64_Qgn5icero6.gif

3.92 KB
Loading

src/color.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ impl CliColorConfig {
143143
"--color=always" => ColorOption::Always,
144144
"--color=never" => ColorOption::Never,
145145
_ => {
146-
eprintln!("Invalid argument: {}", arg);
147-
eprintln!("Usage: my_program [--color=always|auto|never]");
148-
eprintln!("Using Default: auto");
149-
146+
// removed error message print
150147
ColorOption::Auto
151148
}
152149
};

0 commit comments

Comments
 (0)