From 521489052d7f14a6e5d3f8814a51b573bece8888 Mon Sep 17 00:00:00 2001 From: Ryan Ciehanski Date: Fri, 3 Mar 2023 11:22:03 -0600 Subject: [PATCH] feat: add helper functions for the user to set label and total --- src/lib.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0c1cd71..7edcb2a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -179,6 +179,16 @@ impl Progress { self.bars[bar.0].curr = value; } + /// Set a particular [`Bar`]'s total progress value. + pub fn set_total(&mut self, bar: &Bar, total: usize) { + self.bars[bar.0].total = total; + } + + /// Set a particular [`Bar`]'s label. + pub fn set_label>(&mut self, bar: &Bar, label: S) { + self.bars[bar.0].label = label.into(); + } + /// Force the drawing of a particular [`Bar`]. /// /// **Note 1:** Drawing will only occur if there is something meaningful to @@ -265,6 +275,20 @@ impl Progress { self.draw(bar); } + /// Set a particular [`Bar`]'s total progress value and immediately + /// try to draw it. + pub fn set_total_and_draw(&mut self, bar: &Bar, total: usize) { + self.set_total(bar, total); + self.draw(bar); + } + + /// Set a particular [`Bar`]'s label and immediately try to + /// draw it. + pub fn set_label_and_draw>(&mut self, bar: &Bar, label: S) { + self.set_label(bar, label); + self.draw(bar); + } + /// Increment a given [`Bar`]'s progress, but don't draw it. pub fn inc(&mut self, bar: &Bar, value: usize) { self.set(bar, self.bars[bar.0].curr + value)