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

Adding ProgressIterator::progress_with_style() and taking care of minor typos and clippy lints #306

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/draw_target.rs
Expand Up @@ -305,7 +305,7 @@ impl MultiProgressState {
let finished = !self
.draw_states
.iter()
.any(|ref x| !x.as_ref().map(|s| s.finished).unwrap_or(false));
.any(|x| !x.as_ref().map(|s| s.finished).unwrap_or(false));
self.draw_target.apply_draw_state(ProgressDrawState {
lines,
orphan_lines: orphan_lines_count,
Expand Down
15 changes: 15 additions & 0 deletions src/iter.rs
Expand Up @@ -33,6 +33,16 @@ where

/// Wrap an iterator with a custom progress bar.
fn progress_with(self, progress: ProgressBar) -> ProgressBarIter<Self>;

/// Wrap an iterator with a progress bar and style it.
fn progress_with_style(self, style: crate::ProgressStyle) -> ProgressBarIter<Self>
where
Self: ExactSizeIterator,
{
let len = u64::try_from(self.len()).unwrap();
let bar = ProgressBar::new(len).with_style(style);
self.progress_with(bar)
}
}

/// Wraps an iterator to display its progress.
Expand Down Expand Up @@ -164,6 +174,7 @@ impl<S, T: Iterator<Item = S>> ProgressIterator for T {

#[cfg(test)]
mod test {
use crate::ProgressStyle;
use crate::iter::{ProgressBarIter, ProgressIterator};
use crate::progress_bar::ProgressBar;

Expand All @@ -180,5 +191,9 @@ mod test {
let pb = ProgressBar::new(v.len() as u64);
v.iter().progress_with(pb)
});
wrap({
let style = ProgressStyle::default_bar().template("{wide_bar:.red} {percent}/100%");
v.iter().progress_with_style(style)
});
}
}
2 changes: 1 addition & 1 deletion src/state.rs
Expand Up @@ -239,7 +239,7 @@ impl ProgressState {
}

let lines = match self.should_render() {
true => self.style.format_state(&self),
true => self.style.format_state(self),
false => Vec::new(),
};

Expand Down
2 changes: 1 addition & 1 deletion src/style.rs
Expand Up @@ -119,7 +119,7 @@ impl ProgressStyle {

/// Sets the progress characters `(filled, current, to do)`
///
/// You can pass more then three for a more detailed display.
/// You can pass more than three for a more detailed display.
/// All passed grapheme clusters need to be of equal width.
pub fn progress_chars(mut self, s: &str) -> ProgressStyle {
self.progress_chars = segment(s);
Expand Down