Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] allow users to set label and total after Bar's initialization #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@ impl Progress {
self.bars[bar.0].curr = value;
}

/// 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;
}

/// 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 +276,20 @@ impl Progress {
self.draw(bar);
}

/// Set a particular [`Bar`]'s progress target value and immediately
/// try to draw it.
pub fn set_target_and_draw(&mut self, bar: &Bar, total: usize) {
self.set_target(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