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 #467 #468
Fix #467 #468
Conversation
It is possible to use |
I thought of implementing |
Uh, I thought we'd just add a |
I forgot to mention it. I'm basing this off |
Well, we should wrap |
I don't know. Is it supposed to work like it does in that test? Or is the test written like that because the inner |
Not sure what you mean exactly. The point here is that I don't want to impose |
I'm sorry if I'm not making sense, I probably don't get how it should to work. Let's suppose there is this #[derive(Debug, Clone)]
struct TestTracker(String);
impl ProgressTracker for TestTracker {
fn clone_box(&self) -> Box<dyn ProgressTracker> {
Box::new(self.clone())
}
fn tick(&mut self, state: &ProgressState, _: Instant) {
self.0.clear();
self.0.push_str(format!("{} {}", state.len().unwrap(), state.pos()).as_str());
}
fn reset(&mut self, _state: &ProgressState, _: Instant) {
self.0.clear();
}
fn write(&self, _state: &ProgressState, w: &mut dyn fmt::Write) {
w.write_str(self.0.as_str()).unwrap()
}
} And, like you said, Arc/Mutex is not imposed on the implementor right now. If we run this: use crate::ProgressBar;
let pb = ProgressBar::new(1);
pb.set_style(
ProgressStyle::with_template("{{ {foo} }}")
.unwrap()
.with_key("foo", TestTracker(String::default()))
.progress_chars("#>-"),
);
let mut buf = Vec::new();
let style = pb.clone().style();
style.format_state(&pb.state().state, &mut buf, 16);
assert_eq!(&buf[0], "{ }");
buf.clear();
pb.inc(1);
style.format_state(&pb.state().state, &mut buf, 16);
assert_eq!(&buf[0], "{ 1 1 }");
pb.reset();
buf.clear();
style.format_state(&pb.state().state, &mut buf, 16);
assert_eq!(&buf[0], "{ }");
pb.finish_and_clear(); The first |
/// Get a clone of the current progress bar style.
pub fn style(self) -> ProgressStyle {
self.state().style.clone()
} Well, then. If the |
We can close this then, right? |
Possible fix for #467.