Skip to content

Commit

Permalink
22 allow skip input validation (#30)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Arteiii authored Apr 23, 2024
1 parent d99c59a commit 20e1995
Show file tree
Hide file tree
Showing 5 changed files with 431 additions and 237 deletions.
37 changes: 22 additions & 15 deletions examples/input.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
use regex::Regex;
use zenity::menu::input::{valid_path, valid_regex};

use zenity::menu::input::{Input, Requirements};

fn main() {
println!("Input Preview:");
println!("\n\nInput Preview:");

let path = Input::new("Enter Valid Path:", Requirements::default()).start();
let path_with_regex = Input::new(
"Enter a Valid .toml file",
Requirements::path()
.set_regex(Regex::new(r"\.toml\z").unwrap())
.set_note("", "Please Enter a Valid Path to a .toml file"),
)
.start();
let regex = Input::new(
"Enter Valid Regex (ABC):",
Requirements::regex(Regex::new(r"^ABC$").unwrap()),
)
.allow_force()
.set_default("ABC")
.start();

println!(
"\n\nReturn: {}",
valid_regex(
"Enter string:",
Regex::new(r"^\d{3}$").unwrap(),
Some("369"),
false
)
);
println!(
"\n\nPath: {:?}",
valid_path("Enter A Valid Path:", None, true)
);
println!("Existing Path: {:?}", path);
println!("Path with Regex: {:?}", path_with_regex);
println!("Regex: {:?}", regex);
}
Binary file modified images/rustrover64_Qgn5icero6.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,7 @@ impl CliColorConfig {
"--color=always" => ColorOption::Always,
"--color=never" => ColorOption::Never,
_ => {
eprintln!("Invalid argument: {}", arg);
eprintln!("Usage: my_program [--color=always|auto|never]");
eprintln!("Using Default: auto");

// removed error message print
ColorOption::Auto
}
};
Expand Down
Loading

0 comments on commit 20e1995

Please sign in to comment.