Skip to content

CatilGrass/just_progress

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

just_progress

Just a progress display tool

Usage

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:

[dependencies]
just_progress = "0.1"

License

This project is dual-licensed under MIT and Apache 2.0. See the LICENSE file for details.

About

Just a progress display tool

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Contributors

Languages