From ac377a9c9ca55ea4d08d240a0db110e700c7c064 Mon Sep 17 00:00:00 2001 From: Nikkuss Date: Tue, 11 Nov 2025 21:41:36 +0000 Subject: [PATCH] edit multibar --- src/main.rs | 11 ++++++++--- src/multibar.rs | 17 ++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 70f3580..bfa6c7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,9 +88,14 @@ fn main() -> Result<(), color_eyre::Report> { // pb.finish_and_clear(); let term = Term::stdout(); let empty = style("-").blue().to_string(); - let bar = - MultiBar([("#", 5), (empty.as_str(), 2), (" ", 3)]).scale(u64::from(term.size().0) / 3); - println!("Bar: [{}]", bar); + let bar = MultiBar([ + ("=", 50, false), + (">", 1, true), + (empty.as_str(), 3, false), + (" ", 30, false), + ]) + .scale(u64::from(term.size().1 - 2)); + println!("[{}]", bar); return Ok(()); let lines = std::fs::read_to_string("build.log")?; diff --git a/src/multibar.rs b/src/multibar.rs index 711ebf3..1e49e4b 100644 --- a/src/multibar.rs +++ b/src/multibar.rs @@ -1,12 +1,12 @@ use std::fmt; #[derive(Debug)] -pub struct MultiBar<'s, const N: usize>(pub [(&'s str, u64); N]); +pub struct MultiBar<'s, const N: usize>(pub [(&'s str, u64, bool); N]); impl MultiBar<'_, N> { /// Total length of the bar pub(crate) fn length(&self) -> u64 { - self.0.iter().map(|(_, len)| *len).sum() + self.0.iter().map(|(_, len, _)| *len).sum::() } /// Transforms the bar to be of target size @@ -15,20 +15,23 @@ impl MultiBar<'_, N> { let mut prev_prop = 0; let mut curr_prop = 0; - let inner = self.0.map(|(c, len)| { + let inner = self.0.map(|(c, len, const_len)| { + if const_len { + return (c, len, const_len); + } curr_prop += len; let nb_chars = size * curr_prop / length - size * prev_prop / length; - prev_prop = curr_prop; - (c, nb_chars) - }); + prev_prop = curr_prop; + (c, nb_chars, const_len) + }); Self(inner) } } impl fmt::Display for MultiBar<'_, N> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - for &(c, len) in &self.0 { + for &(c, len, _) in &self.0 { for _ in 0..len { f.write_str(c)?; }