Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add style key for speed in steps/bytes per second (#108)
- Loading branch information
Showing
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use std::cmp::min; | ||
use std::thread; | ||
use std::time::Duration; | ||
|
||
use indicatif::{ProgressBar, ProgressStyle}; | ||
|
||
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} ({bytes_per_sec}, {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(12)); | ||
} | ||
|
||
pb.finish_with_message("downloaded"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters