From 05b7b483056902a07f83bc14f443ab59ce1471d8 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 28 Feb 2026 18:01:33 +0800 Subject: First version --- README.md | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 README.md (limited to 'README.md') diff --git a/README.md b/README.md new file mode 100644 index 0000000..517ae53 --- /dev/null +++ b/README.md @@ -0,0 +1,97 @@ +# just_progress + +> Just a progress display tool + +## Usage + +```rust +use just_progress::progress; +use just_progress::renderer::ProgressSimpleRenderer; +use tokio::time::{sleep, Duration}; +use tokio::join; + +#[tokio::main] +async fn main() { + // Initialize the progress center + let center = progress::init(); + + // Create a renderer and enable subprogress display + let renderer = ProgressSimpleRenderer::new().with_subprogress(true); + + // Bind the renderer callback function + let bind = progress::bind(center, move |name, state| renderer.update(name, state)); + + // Concurrently execute progress binding and business logic + join!(bind, proc()); +} + +async fn proc() { + println!("Starting package download!"); + sleep(Duration::from_millis(500)).await; + + // Define multiple concurrent download tasks + let download_task = async { + for i in 1..21 { + sleep(Duration::from_millis(50)).await; + progress::update_progress("Download/Data", i as f32 * 0.05); + } + }; + + let extract_task = async { + for i in 1..11 { + sleep(Duration::from_millis(100)).await; + progress::update_progress("Download/Extract", i as f32 * 0.1); + } + }; + + let verify_sha256_task = async { + for i in 1..6 { + sleep(Duration::from_millis(300)).await; + progress::update_progress("Download/Verify/SHA256", i as f32 * 0.2); + } + }; + + let verify_md5_task = async { + for i in 1..6 { + sleep(Duration::from_millis(100)).await; + progress::update_progress("Download/Verify/MD5", i as f32 * 0.2); + } + }; + + let verify_blake3_task = async { + for i in 1..6 { + sleep(Duration::from_millis(500)).await; + progress::update_progress("Download/Verify/Blake3", i as f32 * 0.2); + } + }; + + // Concurrently execute all download tasks + join!( + download_task, + extract_task, + verify_sha256_task, + verify_blake3_task, + verify_md5_task + ); + + sleep(Duration::from_millis(500)).await; + progress::clear_all(); // Clear all progress after download completes + println!("Package download complete!"); + + progress::close(); // Close the progress channel, ending the program +} +``` + +## Installation + +Add this to your `Cargo.toml`: + +```toml +[dependencies] +just_progress = "0.1" +``` + +## License + +This project is dual-licensed under MIT and Apache 2.0. +See the LICENSE file for details. -- cgit