Skip to content

Commit

Permalink
feat: add helper functions for the user to set label and total
Browse files Browse the repository at this point in the history
  • Loading branch information
ciehanski committed Mar 3, 2023
1 parent db73aae commit 5214890
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Into<String>>(&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
Expand Down Expand Up @@ -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<S: Into<String>>(&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)
Expand Down

0 comments on commit 5214890

Please sign in to comment.