Skip to content

Commit

Permalink
32 requirenents (#34)
Browse files Browse the repository at this point in the history
* Update README.md
* added custom log render
* added log an requirement checks
* fixed panic if get_last was called while no spinner was created
  • Loading branch information
Arteiii authored May 1, 2024
1 parent c8eb380 commit 02cb47b
Show file tree
Hide file tree
Showing 14 changed files with 567 additions and 38 deletions.
8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ test = true


[features]
default = ["spinner", "progressbar", "menu"]
default = ["spinner", "progressbar", "menu", "log"]

spinner = []
progressbar = []
menu = []
menu = ["spinner"]
log = []


[dependencies]
crossterm = "0.27.0"
supports-color = "3.0.0"
lazy_static = "1.4.0"
regex = "1.10.4"
log = { version = "0.4.21", features = ["std"] }
chrono = "0.4.38"


[dev-dependencies]
rand = "0.8.5"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<img src="images/ZENITY.svg" alt="Zenity svg logo" width="400">
<p>Yet Another Spinner Lib</p>
<p style="margin-top: -10px;">Elevate your Rust command-line interfaces with 100+ spinner animations and Progress Bars + multiline support</p>
<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>
<a href="https://github.com/Arteiii/zenity/actions/workflows/publish_crate.yml">
<img src="https://github.com/Arteiii/zenity/actions/workflows/publish_crate.yml/badge.svg" alt="Publish to Crates">
</a>
Expand Down
3 changes: 2 additions & 1 deletion examples/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ static TOTAL_ANIMATIONS: AtomicUsize = AtomicUsize::new(0);

macro_rules! test_predefined_animation {
($animation:expr, $text:expr) => {{
let custom = MultiSpinner::new($animation);
let custom = MultiSpinner::new();
custom.add($animation);
custom.run_all();
custom.set_text(&custom.get_last(), $text.to_string());
sleep(Duration::from_secs(5));
Expand Down
3 changes: 2 additions & 1 deletion examples/custom_frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ fn main() {
};

// create a MultiSpinner instance using the new custom animation
let spinner = MultiSpinner::new(custom_frames);
let spinner = MultiSpinner::new();
spinner.add(custom_frames);
spinner.run_all();

// wait for 5 seconds to showcase the loading animation with the custom animation
Expand Down
42 changes: 42 additions & 0 deletions examples/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use log::Level;

use zenity::log::Logger;

mod foo {
mod bar {
pub fn run() {
log::error!("[bar] error");
log::warn!("[bar] warn");
log::info!("[bar] info");
log::debug!("[bar] debug");
log::trace!("[bar] trace");
}
}

pub fn run() {
log::error!("[foo] error");
log::warn!("[foo] warn");
log::info!("[foo] info");
log::debug!("[foo] debug");
log::trace!("[foo] trace");
bar::run();
}
}

fn main() {
// Set the custom logger as the global logger
Logger::new()
.with_env("TEST_LEVEL")
.with_arg()
.set_log_level(Level::Trace)
.init()
.unwrap();

// Now you can use log::debug! to output messages
log::error!("[root] This is a error message");
log::warn!("[root] This is a warn message");
log::info!("[root] This is a info message");
log::debug!("[root] This is a debug message");
log::trace!("[root] This is a trace message");
foo::run();
}
8 changes: 8 additions & 0 deletions examples/requirements.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use zenity::menu::requirements;

fn main() {
match requirements::verify_requirements(vec!["uidmap", "bridge-utils"]) {
Ok(_) => println!("All required packages are installed."),
Err(err) => eprintln!("Error verifying requirements: {}", err),
}
}
24 changes: 14 additions & 10 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,24 @@ impl CliColorConfig {
}
}

/// parse args to check for --color=always|auto|never
/// parse args to check for --color=always|auto|never
fn parse_arguments(args: &[String]) -> ColorOption {
if args.len() > 1 {
let arg = &args[1];
return match arg.as_str() {
"--color=always" => ColorOption::Always,
"--color=never" => ColorOption::Never,
_ => {
// removed error message print
ColorOption::Auto
}
};
for arg in args.iter() {
if arg.starts_with("--color=") {
return match arg.split('=').nth(1) {
Some("always") => ColorOption::Always,
Some("auto") => ColorOption::Auto,
Some("never") => ColorOption::Never,
_ => {
ColorOption::Auto // Default to Auto in case of invalid option
}
};
}
}

// If no color option is found, default to Auto
ColorOption::Auto
}

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub mod progress;
#[cfg(feature = "spinner")]
pub mod spinner;

#[cfg(feature = "log")]
pub mod log;

// Crate
pub(crate) mod iterators;
pub(crate) mod terminal;
Loading

0 comments on commit 02cb47b

Please sign in to comment.