From 933f17932841c8fe8206744fccec8a38eeca96df Mon Sep 17 00:00:00 2001 From: Nick Pegg Date: Wed, 7 May 2025 21:29:50 -0700 Subject: [PATCH] add image rendering progress bar --- Cargo.lock | 67 ++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 1 + src/generate.rs | 15 ++++++++--- src/main.rs | 1 + 4 files changed, 80 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae9e3fa..473de73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -277,6 +277,19 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "unicode-width 0.2.0", + "windows-sys", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -352,6 +365,12 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + [[package]] name = "env_filter" version = "0.1.3" @@ -437,7 +456,7 @@ version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" dependencies = [ - "unicode-width", + "unicode-width 0.1.14", ] [[package]] @@ -584,6 +603,19 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indicatif" +version = "0.17.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width 0.2.0", + "web-time", +] + [[package]] name = "interpolate_name" version = "0.2.4" @@ -656,6 +688,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f5d4a7da358eff58addd2877a45865158f0d78c911d43a5784ceb7bbf52833b0" +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -822,6 +864,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + [[package]] name = "once_cell" version = "1.21.3" @@ -888,6 +936,7 @@ dependencies = [ "env_logger", "fs_extra", "image", + "indicatif", "log", "mktemp", "pulldown-cmark", @@ -1485,6 +1534,12 @@ version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + [[package]] name = "utf8parse" version = "0.2.2" @@ -1606,6 +1661,16 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "weezl" version = "0.1.8" diff --git a/Cargo.toml b/Cargo.toml index 9415881..bc31a2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ clap = { version = "^4.5", features = ["derive"] } env_logger = "^0.11.8" fs_extra = "^1.3.0" image = "^0.25.6" +indicatif = "^0.17.11" log = "^0.4.27" pulldown-cmark = "^0.13.0" rayon = "^1.10.0" diff --git a/src/generate.rs b/src/generate.rs index 119e4fc..4acc29f 100644 --- a/src/generate.rs +++ b/src/generate.rs @@ -4,6 +4,7 @@ use crate::config::Config; use album_dir::{AlbumDir, Image}; use anyhow::anyhow; use image::imageops::FilterType; +use indicatif::ProgressBar; use rayon::prelude::*; use serde::Serialize; use std::collections::VecDeque; @@ -156,13 +157,14 @@ fn copy_static(config: &Config) -> anyhow::Result<()> { fn generate_images(config: &Config, album: &AlbumDir, full: bool) -> anyhow::Result<()> { let output_path = album.path.join(&config.output_dir); - // TODO: progress bar ? let mut all_images: Vec<&Image> = album.iter_all_images().collect(); // also resize cover image all_images.push(&album.cover); - all_images.par_iter().try_for_each(|img| { + println!("Generating images..."); + let progress = ProgressBar::new(all_images.len() as u64); + let result = all_images.par_iter().try_for_each(|img| { let full_size_path = output_path.join(&img.path); if !full && full_size_path.exists() @@ -171,6 +173,7 @@ fn generate_images(config: &Config, album: &AlbumDir, full: bool) -> anyhow::Res log::info!("Skipping {}, already generated", img.path.display()); return Ok(()); } + log::info!( "Copying original {} -> {}", img.path.display(), @@ -209,8 +212,12 @@ fn generate_images(config: &Config, album: &AlbumDir, full: bool) -> anyhow::Res .resize(config.view_size.0, config.view_size.1, IMG_RESIZE_FILTER) .save(&screen_path)?; + progress.inc(1); Ok(()) - }) + }); + progress.finish(); + + result } fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> { @@ -223,6 +230,8 @@ fn generate_html(config: &Config, album: &AlbumDir) -> anyhow::Result<()> { .ok_or(anyhow!("Missing _templates dir in album dir"))?, )?; + println!("Generating HTML..."); + let mut dir_queue: VecDeque<&AlbumDir> = VecDeque::from([album]); while let Some(album) = dir_queue.pop_front() { let html_path = output_path.join(&album.path).join("index.html"); diff --git a/src/main.rs b/src/main.rs index f4c6e33..cf1a837 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use std::path::Path; fn main() -> anyhow::Result<()> { env_logger::init(); + let cli = Cli::parse(); let album_path = Path::new(&cli.album_path).canonicalize()?;