From 3cc413f1f0dad509abc74da4c11dd26696100d8c Mon Sep 17 00:00:00 2001 From: Drew Short Date: Sun, 31 May 2020 21:02:16 -0500 Subject: [PATCH] Cleanup download progress --- src/main.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index dc147d1..5c6cfb6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -127,6 +127,7 @@ fn download_command( Err(e) => println!("Error setting progress setting: {}", e), Ok(_) => (), }; + let mut progress_length: usize = 0; match easy.progress_function( move |total_bytes_to_download, bytes_downloaded, @@ -134,13 +135,23 @@ fn download_command( _bytes_uploaded| { let percentage = calculate_percentage(bytes_downloaded, total_bytes_to_download); - match print_progress( - format!( - "{}: {:.2}% {}", - progress_filename, percentage, &progress_count - ) - .as_bytes(), - ) { + let mut progress = format!( + "{}: {:.2}% {}", + progress_filename, percentage, &progress_count + ); + progress_length = if progress.len() > progress_length { + progress.len() + } else { + progress_length + }; + if progress_length > progress.len() { + progress = format!( + "{}{}", + progress, + " ".repeat(progress_length - progress.len()) + ); + } + match print_progress(progress.as_bytes()) { Err(e) => println!("Error showing downloading progress: {}", e), Ok(_) => (), }; @@ -176,8 +187,9 @@ fn download_command( state_manager.save(new_state); println!( "Downloaded {:#?}/{:#?} images", - favorites_downloaded_count, all_downloaded_count - ) + favorites_downloaded_count, to_download_count + ); + println!("Total Downloaded: {:#?}", all_downloaded_count); } fn favorites_command(backup: model::anime_boxes::Backup) {