From 521489052d7f14a6e5d3f8814a51b573bece8888 Mon Sep 17 00:00:00 2001 From: Ryan Ciehanski Date: Fri, 3 Mar 2023 11:22:03 -0600 Subject: [PATCH 1/2] 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) From f497d457c7b7e445f7e598e47b2a5ce633780abc Mon Sep 17 00:00:00 2001 From: Ryan Ciehanski Date: Mon, 15 May 2023 23:39:05 -0500 Subject: [PATCH 2/2] chore: update func names from total to target --- src/lib.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7edcb2a..735592d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -179,8 +179,9 @@ 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) { + /// Set a particular [`Bar`]'s progress target value. + /// Useful in cases where you don't know the total ahead of time. + pub fn set_target(&mut self, bar: &Bar, total: usize) { self.bars[bar.0].total = total; } @@ -275,10 +276,10 @@ impl Progress { self.draw(bar); } - /// Set a particular [`Bar`]'s total progress value and immediately + /// Set a particular [`Bar`]'s progress target value and immediately /// try to draw it. - pub fn set_total_and_draw(&mut self, bar: &Bar, total: usize) { - self.set_total(bar, total); + pub fn set_target_and_draw(&mut self, bar: &Bar, total: usize) { + self.set_target(bar, total); self.draw(bar); }