Which library does the progress bar depend on in cargo? I want to add a progress bar to my project, so I want to learn from it.
It looks like they implemented their own progress bar. I'm guessing that's because nothing existed that quite fit their needs when first implementing cargo.
fn print(&mut self, prefix: &str, msg: &str) -> CargoResult<()> {
self.throttle.update();
self.try_update_max_width();
// make sure we have enough room for the header
if self.format.max_width < 15 {
return Ok(());
}
let mut line = prefix.to_string();
self.format.render(&mut line, msg);
while line.len() < self.format.max_width - 15 {
line.push(' ');
}
// Only update if the line has changed.
if self.config.shell().is_cleared() || self.last_line.as_ref() != Some(&line) {
let mut shell = self.config.shell();
shell.set_needs_clear(false);
shell.status_header(&self.name)?;
This file has been truncated. show original
In the past, I've found the indicatif crate to be quite nice to work with and generate pretty output.
H2CO3
January 5, 2022, 5:15pm
3
+1 to indicatif, that's the one I think has the best bang for the buck, in terms of features/nice display vs. API complexity/usability.