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

fix #341: make is_hidden() work for MultiProgress #430

Merged
merged 1 commit into from May 12, 2022
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions src/draw_target.rs
Expand Up @@ -102,6 +102,7 @@ impl ProgressDrawTarget {
match self.kind {
TargetKind::Hidden => true,
TargetKind::Term { ref term, .. } => !term.is_term(),
TargetKind::Multi { ref state, .. } => state.read().unwrap().is_hidden(),
_ => false,
}
}
Expand Down Expand Up @@ -434,3 +435,17 @@ impl DrawState {
self.orphan_lines = 0;
}
}

#[cfg(test)]
mod tests {
use crate::{MultiProgress, ProgressBar, ProgressDrawTarget};

#[test]
fn multi_is_hidden() {
let mp = MultiProgress::with_draw_target(ProgressDrawTarget::hidden());

let pb = mp.add(ProgressBar::new(100));
assert!(mp.is_hidden());
assert!(pb.is_hidden());
}
}
8 changes: 8 additions & 0 deletions src/multi.rs
Expand Up @@ -159,6 +159,10 @@ impl MultiProgress {
pub fn clear(&self) -> io::Result<()> {
self.state.write().unwrap().clear(Instant::now())
}

pub fn is_hidden(&self) -> bool {
self.state.read().unwrap().is_hidden()
}
}

#[derive(Debug)]
Expand Down Expand Up @@ -256,6 +260,10 @@ impl MultiState {
DrawStateWrapper::for_multi(state, orphans)
}

pub(crate) fn is_hidden(&self) -> bool {
self.draw_target.is_hidden()
}

pub(crate) fn suspend<F: FnOnce() -> R, R>(&mut self, f: F, now: Instant) -> R {
self.clear(now).unwrap();
let ret = f();
Expand Down