Skip to content

Commit

Permalink
Add ProgressDrawTarget::std{out,err}_with_hz convenience functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mibac138 committed Jun 7, 2019
1 parent d9be810 commit 1fb76cb
Showing 1 changed file with 22 additions and 4 deletions.
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<RR: Into<Option<u64>>>(
term: Term,
refresh_rate: RR,
) -> ProgressDrawTarget {
let rate = refresh_rate.into()
.map(|x| Duration::from_millis(1000 / x));
ProgressDrawTarget {
kind: ProgressDrawTargetKind::Term(term, None, rate),
}
Expand Down

0 comments on commit 1fb76cb

Please sign in to comment.