Skip to content

Commit

Permalink
Make ceprint! use cformat!
Browse files Browse the repository at this point in the history
  • Loading branch information
Sellig6792 committed May 3, 2024
1 parent ffd9f45 commit 8593142
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ default = ["cprint"]
coloration = []
cformat = ["coloration"]
cprint = ["coloration", "cformat"]
ceprint = ["coloration"]
ceprint = ["coloration", "cformat"]

[package.metadata.docs.rs]
all-features = true
Expand Down
25 changes: 2 additions & 23 deletions src/ceprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,10 @@ macro_rules! ceprint {
($msg:expr) => {{
use $crate::coloration::{colorize_string, Color::Red};

let mut still_at_start = true;

let white_spaces = $msg
.chars()
.filter_map(|c| {
if c.is_whitespace() && still_at_start {
Some(c)
} else {
still_at_start = false;
None
}
})
.collect::<String>();
let white_spaces = $crate::_get_white_spaces_at_start!($msg);
let msg = $msg.trim_start();

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

Expand Down
14 changes: 1 addition & 13 deletions src/cformat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ macro_rules! cformat {
($title:expr, $msg:expr, $color:expr) => {{
use $crate::coloration::Coloration;

let mut still_at_start = true;

let white_spaces = $title
.chars()
.filter_map(|c| {
if c.is_whitespace() && still_at_start {
Some(c)
} else {
still_at_start = false;
None
}
})
.collect::<String>();
let white_spaces = $crate::_get_white_spaces_at_start!($title);
let title = $title.trim_start();

format!(
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ mod ceprint;

#[cfg(feature = "cformat")]
mod cformat;

#[cfg(any(feature = "cprint", feature = "ceprint", feature = "cformat"))]
mod utils;
18 changes: 18 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[macro_export]
macro_rules! _get_white_spaces_at_start {
($text:expr) => {{
let mut still_at_start = true;

$text
.chars()
.filter_map(|c| {
if c.is_whitespace() && still_at_start {
Some(c)
} else {
still_at_start = false;
None
}
})
.collect::<String>()
}};
}

0 comments on commit 8593142

Please sign in to comment.