Skip to content

Commit 02cb47b

Browse files
authored
32 requirenents (#34)
* Update README.md * added custom log render * added log an requirement checks * fixed panic if get_last was called while no spinner was created
1 parent c8eb380 commit 02cb47b

14 files changed

Lines changed: 567 additions & 38 deletions

File tree

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,22 @@ test = true
2626

2727

2828
[features]
29-
default = ["spinner", "progressbar", "menu"]
29+
default = ["spinner", "progressbar", "menu", "log"]
3030

3131
spinner = []
3232
progressbar = []
33-
menu = []
33+
menu = ["spinner"]
34+
log = []
3435

3536

3637
[dependencies]
3738
crossterm = "0.27.0"
3839
supports-color = "3.0.0"
3940
lazy_static = "1.4.0"
4041
regex = "1.10.4"
42+
log = { version = "0.4.21", features = ["std"] }
43+
chrono = "0.4.38"
44+
4145

4246
[dev-dependencies]
4347
rand = "0.8.5"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div align="center">
22
<img src="images/ZENITY.svg" alt="Zenity svg logo" width="400">
33
<p>Yet Another Spinner Lib</p>
4-
<p style="margin-top: -10px;">Elevate your Rust command-line interfaces with 100+ spinner animations and Progress Bars + multiline support</p>
4+
<p style="margin-top: -10px;">Upgrade your Rust CLIs with 100+ spinner animations, progress bars, and multiline support, plus user input validation, logging, and automatic requirement checks</p>
55
<a href="https://github.com/Arteiii/zenity/actions/workflows/publish_crate.yml">
66
<img src="https://github.com/Arteiii/zenity/actions/workflows/publish_crate.yml/badge.svg" alt="Publish to Crates">
77
</a>

examples/all.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ static TOTAL_ANIMATIONS: AtomicUsize = AtomicUsize::new(0);
88

99
macro_rules! test_predefined_animation {
1010
($animation:expr, $text:expr) => {{
11-
let custom = MultiSpinner::new($animation);
11+
let custom = MultiSpinner::new();
12+
custom.add($animation);
1213
custom.run_all();
1314
custom.set_text(&custom.get_last(), $text.to_string());
1415
sleep(Duration::from_secs(5));

examples/custom_frames.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ fn main() {
1515
};
1616

1717
// create a MultiSpinner instance using the new custom animation
18-
let spinner = MultiSpinner::new(custom_frames);
18+
let spinner = MultiSpinner::new();
19+
spinner.add(custom_frames);
1920
spinner.run_all();
2021

2122
// wait for 5 seconds to showcase the loading animation with the custom animation

examples/log.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use log::Level;
2+
3+
use zenity::log::Logger;
4+
5+
mod foo {
6+
mod bar {
7+
pub fn run() {
8+
log::error!("[bar] error");
9+
log::warn!("[bar] warn");
10+
log::info!("[bar] info");
11+
log::debug!("[bar] debug");
12+
log::trace!("[bar] trace");
13+
}
14+
}
15+
16+
pub fn run() {
17+
log::error!("[foo] error");
18+
log::warn!("[foo] warn");
19+
log::info!("[foo] info");
20+
log::debug!("[foo] debug");
21+
log::trace!("[foo] trace");
22+
bar::run();
23+
}
24+
}
25+
26+
fn main() {
27+
// Set the custom logger as the global logger
28+
Logger::new()
29+
.with_env("TEST_LEVEL")
30+
.with_arg()
31+
.set_log_level(Level::Trace)
32+
.init()
33+
.unwrap();
34+
35+
// Now you can use log::debug! to output messages
36+
log::error!("[root] This is a error message");
37+
log::warn!("[root] This is a warn message");
38+
log::info!("[root] This is a info message");
39+
log::debug!("[root] This is a debug message");
40+
log::trace!("[root] This is a trace message");
41+
foo::run();
42+
}

examples/requirements.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use zenity::menu::requirements;
2+
3+
fn main() {
4+
match requirements::verify_requirements(vec!["uidmap", "bridge-utils"]) {
5+
Ok(_) => println!("All required packages are installed."),
6+
Err(err) => eprintln!("Error verifying requirements: {}", err),
7+
}
8+
}

src/color.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,24 @@ impl CliColorConfig {
135135
}
136136
}
137137

138+
/// parse args to check for --color=always|auto|never
139+
138140
/// parse args to check for --color=always|auto|never
139141
fn parse_arguments(args: &[String]) -> ColorOption {
140-
if args.len() > 1 {
141-
let arg = &args[1];
142-
return match arg.as_str() {
143-
"--color=always" => ColorOption::Always,
144-
"--color=never" => ColorOption::Never,
145-
_ => {
146-
// removed error message print
147-
ColorOption::Auto
148-
}
149-
};
142+
for arg in args.iter() {
143+
if arg.starts_with("--color=") {
144+
return match arg.split('=').nth(1) {
145+
Some("always") => ColorOption::Always,
146+
Some("auto") => ColorOption::Auto,
147+
Some("never") => ColorOption::Never,
148+
_ => {
149+
ColorOption::Auto // Default to Auto in case of invalid option
150+
}
151+
};
152+
}
150153
}
151154

155+
// If no color option is found, default to Auto
152156
ColorOption::Auto
153157
}
154158

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ pub mod progress;
9292
#[cfg(feature = "spinner")]
9393
pub mod spinner;
9494

95+
#[cfg(feature = "log")]
96+
pub mod log;
97+
9598
// Crate
9699
pub(crate) mod iterators;
97100
pub(crate) mod terminal;

0 commit comments

Comments
 (0)