From 51b2659dcce46c29eea455aa5eba5e9741d065f0 Mon Sep 17 00:00:00 2001 From: Gilles Meunier Date: Thu, 2 May 2024 19:22:07 +0200 Subject: [PATCH] Fix misaligned output with `ceprint!` for message with spaces --- src/ceprint/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ceprint/mod.rs b/src/ceprint/mod.rs index 39ec503..c04ae26 100644 --- a/src/ceprint/mod.rs +++ b/src/ceprint/mod.rs @@ -11,9 +11,18 @@ macro_rules! ceprint { ($msg:expr) => {{ use $crate::coloration::{colorize_string, Color::Red}; + let mut still_at_start = true; + let white_spaces = $msg .chars() - .filter(|c| c.is_whitespace()) + .filter_map(|c| { + if c.is_whitespace() && still_at_start { + Some(c) + } else { + still_at_start = false; + None + } + }) .collect::(); let msg = $msg.trim_start();