add indicatif
This commit is contained in:
10
indicatif/Cargo.toml
Normal file
10
indicatif/Cargo.toml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[package]
|
||||||
|
name = "indicatif"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
indicatif = "0.13.0"
|
||||||
38
indicatif/src/main.rs
Normal file
38
indicatif/src/main.rs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
use std::{
|
||||||
|
cmp::min,
|
||||||
|
thread,
|
||||||
|
time::Duration
|
||||||
|
};
|
||||||
|
use indicatif::{
|
||||||
|
ProgressBar,
|
||||||
|
ProgressStyle
|
||||||
|
};
|
||||||
|
|
||||||
|
// https://crates.io/crates/indicatif
|
||||||
|
fn main() {
|
||||||
|
let mut downloaded = 0;
|
||||||
|
let total_size = 231231231;
|
||||||
|
|
||||||
|
let pb = ProgressBar::new(total_size);
|
||||||
|
pb.set_style(ProgressStyle::default_bar()
|
||||||
|
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta})")
|
||||||
|
.progress_chars("#>-"));
|
||||||
|
|
||||||
|
while downloaded < total_size {
|
||||||
|
let new = min(downloaded + 223211, total_size);
|
||||||
|
downloaded = new;
|
||||||
|
pb.set_position(new);
|
||||||
|
thread::sleep(Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
pb.finish();
|
||||||
|
// pb.finish_with_message("downloaded");
|
||||||
|
|
||||||
|
let pb2 = ProgressBar::new(1024);
|
||||||
|
for _ in 0..1024 {
|
||||||
|
pb2.inc(1);
|
||||||
|
thread::sleep(Duration::from_millis(5));
|
||||||
|
}
|
||||||
|
pb2.finish();
|
||||||
|
// pb2.finish_with_message("done");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user