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

Add ProgressDrawTarget::std{out,err}_with_hz convenience functions #106

Merged
merged 1 commit into from Sep 7, 2019
Merged
Changes from all 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
26 changes: 22 additions & 4 deletions src/progress.rs
Expand Up @@ -57,15 +57,29 @@ impl ProgressDrawTarget {
///
/// For more information see `ProgressDrawTarget::to_term`.
pub fn stdout() -> ProgressDrawTarget {
ProgressDrawTarget::to_term(Term::buffered_stdout(), Some(15))
ProgressDrawTarget::to_term(Term::buffered_stdout(), 15)
}

/// Draw to a buffered stderr terminal at a max of 15 times a second.
///
/// This is the default draw target for progress bars. For more
/// information see `ProgressDrawTarget::to_term`.
pub fn stderr() -> ProgressDrawTarget {
ProgressDrawTarget::to_term(Term::buffered_stderr(), Some(15))
ProgressDrawTarget::to_term(Term::buffered_stderr(), 15)
}

/// Draw to a buffered stdout terminal at a max of `refresh_rate` times a second.
///
/// For more information see `ProgressDrawTarget::to_term`.
pub fn stdout_with_hz(refresh_rate: u64) -> ProgressDrawTarget {
ProgressDrawTarget::to_term(Term::buffered_stdout(), refresh_rate)
}

/// Draw to a buffered stderr terminal at a max of `refresh_rate` times a second.
///
/// For more information see `ProgressDrawTarget::to_term`.
pub fn stderr_with_hz(refresh_rate: u64) -> ProgressDrawTarget {
ProgressDrawTarget::to_term(Term::buffered_stderr(), refresh_rate)
}

/// Draw to a buffered stdout terminal without max framerate.
Expand Down Expand Up @@ -96,8 +110,12 @@ impl ProgressDrawTarget {
/// terminal is not user attended the entire progress bar will be
/// hidden. This is done so that piping to a file will not produce
/// useless escape codes in that file.
pub fn to_term(term: Term, refresh_rate: Option<u64>) -> ProgressDrawTarget {
let rate = refresh_rate.map(|x| Duration::from_millis(1000 / x));
pub fn to_term(
term: Term,
refresh_rate: impl Into<Option<u64>>,
) -> ProgressDrawTarget {
let rate = refresh_rate.into()
.map(|x| Duration::from_millis(1000 / x));
ProgressDrawTarget {
kind: ProgressDrawTargetKind::Term(term, None, rate),
}
Expand Down