Skip to content

Commit

Permalink
Update indicatif to latest api version
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Bottriell <rbottriell@ilm.com>
  • Loading branch information
rydrman committed Jul 5, 2023
1 parent 55a9b7c commit 571042d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 37 deletions.
15 changes: 11 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dyn-clone = "1.0"
expanduser = "1.2"
futures = "0.3.24"
fuser = "0.12"
indicatif = "0.16.2"
indicatif = "0.17.5"
lazy_static = "1.4"
libc = "0.2.80"
nix = "0.26.2"
Expand Down
4 changes: 2 additions & 2 deletions crates/progress_bar_derive_macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ proc-macro = true
[dependencies]
syn = "2.0"
quote = "1.0"
indicatif = { workspace = true }

[dev-dependencies]
indicatif = { workspace = true }
tracing = { workspace = true }
tracing = { workspace = true }
33 changes: 8 additions & 25 deletions crates/progress_bar_derive_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ use proc_macro::TokenStream;
use quote::{format_ident, quote};
use syn::LitStr;

/// Derive macro for generating boilerplate `Default` and `Drop` impls
/// for a struct with `indicatif::ProgressBar` fields.
/// Derive macro for generating boilerplate [`Default`] and [`Drop`] impls
/// for a struct with [`indicatif::ProgressBar`] fields.
///
/// The struct is required to have a field named `renderer` and one or more
/// fields of type `indicatif::ProgressBar`. Each progress bar field requires
/// a `#[progress_bar]` attribute with a `message` argument. A `template`
/// argument is also required either at the struct level or the field level.
/// The struct is required to have one or more fields of type [`indicatif::ProgressBar`].
/// Each progress bar field requires a `#[progress_bar]` attribute with a `message`
/// argument. A `template` argument is also required either at the struct level or
/// the field level.
///
/// # Example
///
/// ```
/// use progress_bar_derive_macro::ProgressBar;
/// #[derive(ProgressBar)]
/// struct MyStruct {
/// renderer: Option<std::thread::JoinHandle<()>>,
/// #[progress_bar(
/// message = "processing widgets",
/// template = " {spinner} {msg:<16.green} [{bar:40.cyan/dim}] {pos:>8}/{len:6}"
Expand Down Expand Up @@ -120,6 +119,7 @@ fn impl_proc_macro_derive(ast: &syn::DeriveInput) -> TokenStream {
bars.push(quote! {
let #ident_style = indicatif::ProgressStyle::default_bar()
.template(#template)
.expect("Invalid progress bar template")
.tick_strings(TICK_STRINGS)
.progress_chars(PROGRESS_CHARS);
let #ident = bars.add(
Expand All @@ -143,26 +143,9 @@ fn impl_proc_macro_derive(ast: &syn::DeriveInput) -> TokenStream {

let bars = indicatif::MultiProgress::new();
#(#bars)*
#(#progress_bar_field_names.enable_steady_tick(100);)*
// the progress bar must be awaited from some thread
// or nothing will be shown in the terminal
let renderer = Some(std::thread::spawn(move || {
if let Err(err) = bars.join() {
tracing::error!("Failed to render commit progress: {}", err);
}
}));
#(#progress_bar_field_names.enable_steady_tick(std::time::Duration::from_millis(100));)*
Self {
#(#progress_bar_field_names,)*
renderer,
}
}
}

impl Drop for #name {
fn drop(&mut self) {
#(self.#progress_bar_field_names.finish_and_clear();)*
if let Some(r) = self.renderer.take() {
let _ = r.join();
}
}
}
Expand Down
1 change: 0 additions & 1 deletion crates/spfs/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ impl CheckReporter for ConsoleCheckReporter {

#[derive(ProgressBar)]
struct ConsoleCheckReporterBars {
renderer: Option<std::thread::JoinHandle<()>>,
#[progress_bar(
message = "scanning objects",
template = " {spinner} {msg:<18.green} {pos:>9} reached in {elapsed:.cyan} [{per_sec}]"
Expand Down
1 change: 0 additions & 1 deletion crates/spfs/src/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,6 @@ impl CleanReporter for ConsoleCleanReporter {
template = " {spinner} {msg:<17.green} {pos:>10.cyan} found {len:>10.yellow} to remove [{per_sec}]"
)]
struct ConsoleCleanReporterBars {
renderer: Option<std::thread::JoinHandle<()>>,
#[progress_bar(message = "cleaning tags")]
tags: indicatif::ProgressBar,
#[progress_bar(message = "cleaning objects")]
Expand Down
1 change: 0 additions & 1 deletion crates/spfs/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ impl CommitReporter for ConsoleCommitReporter {
#[derive(ProgressBar)]
#[progress_bar(template = " {spinner} {msg:<18.green} [{bar:40.cyan/dim}] {pos:>8}/{len:6}")]
struct ConsoleCommitReporterBars {
renderer: Option<std::thread::JoinHandle<()>>,
#[progress_bar(message = "computing manifest")]
entries: indicatif::ProgressBar,
#[progress_bar(message = "committing blobs")]
Expand Down
1 change: 0 additions & 1 deletion crates/spfs/src/storage/fs/render_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl RenderReporter for ConsoleRenderReporter {
#[derive(ProgressBar)]
#[progress_bar(template = " {spinner} {msg:<16.green} [{bar:40.cyan/dim}] {pos:>8}/{len:6}")]
struct ConsoleRenderReporterBars {
renderer: Option<std::thread::JoinHandle<()>>,
#[progress_bar(message = "rendering layers")]
layers: indicatif::ProgressBar,
#[progress_bar(message = "rendering entries")]
Expand Down
1 change: 0 additions & 1 deletion crates/spfs/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ impl SyncReporter for ConsoleSyncReporter {

#[derive(ProgressBar)]
struct ConsoleSyncReporterBars {
renderer: Option<std::thread::JoinHandle<()>>,
#[progress_bar(
message = "syncing layers",
template = " {spinner} {msg:<16.green} [{bar:40.cyan/dim}] {pos:>8}/{len:6}"
Expand Down

0 comments on commit 571042d

Please sign in to comment.