Skip to content

Commit

Permalink
Merge pull request #30 from Sellig6792/develop
Browse files Browse the repository at this point in the history
v0.4.0
  • Loading branch information
Sellig6792 committed Feb 1, 2023
2 parents efa8679 + 57cf0c1 commit 290d5b8
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cprint"
description = "Cargo-like print"
version = "0.3.1"
version = "0.4.0"
edition = "2021"
authors = ["Sellig6792 <sellig6792@gmail.com>"]
homepage = "https://github.com/Sellig6792/cprint"
Expand Down
17 changes: 12 additions & 5 deletions src/ceprint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@
/// ```
#[macro_export]
macro_rules! ceprint {
($msg:expr) => {
($msg:expr) => {{
use $crate::coloration::{colorize_string, Color::Red};

print!(
"{} {}",
format!("{}{}", " ".repeat(12 - "Error".len()), "Error").apply_color(Color::Red),
format!(
"{}{}",
" ".repeat(12 - "Error".len()),
colorize_string("Error", Red)
),
$msg
);
};
}};
}

/// Same as [`ceprint!`] but with a newline at the end.
#[macro_export]
macro_rules! ceprintln {
($title:expr, $msg:expr) => {
ceprintln!($title, $msg, Color::Red);
($msg:expr) => {
$crate::ceprint!($msg);
println!();
};
}
11 changes: 10 additions & 1 deletion src/coloration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ where
}
}

pub fn colorize_string<FS, ColorType>(string: &FS, color: ColorType) -> ColoredString
where
FS: AsRef<str> + ?Sized,
ColorType: Into<Color>,
{
string.apply_color(color)
}

#[cfg(test)]
mod tests {
use super::*;
use colored::Colorize;

use super::*;

#[test]
fn coloration_trait_with_str() {
let a = "Hello".apply_color(Color::Red);
Expand Down
6 changes: 4 additions & 2 deletions src/cprint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
/// ```
#[macro_export]
macro_rules! cprint {
($title:expr, $msg:expr, $color:expr) => {
($title:expr, $msg:expr, $color:expr) => {{
use $crate::coloration::Coloration;

print!(
"{} {}",
format!("{}{}", " ".repeat(12 - $title.len()), $title).apply_color($color),
$msg
);
};
}};
}

/// Same as [`cprint!`] but with a newline at the end.
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
//! ```

#[cfg(feature = "coloration")]
mod coloration;
pub use coloration::{Color, Coloration};

#[cfg(feature = "coloration")]
pub use coloration::{Color, Coloration};
pub mod coloration;

#[cfg(feature = "cprint")]
mod cprint_macros;
Expand Down

0 comments on commit 290d5b8

Please sign in to comment.