Progress Bar: Updated function to not duplicate writing
Previously when the number of MiBs was shorter the previous writing would not be cleared.
This commit is contained in:
parent
f5d538febe
commit
e8436bd40e
5
main.cpp
5
main.cpp
|
@ -64,11 +64,13 @@ const double number_chars = 100;
|
||||||
const char* full_character = "▓";
|
const char* full_character = "▓";
|
||||||
const char* empty_character = "░";
|
const char* empty_character = "░";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int progress_func(void* ptr, double TotalToDownload, double NowDownloaded, double TotalToUpload, double NowUploaded)
|
int progress_func(void* ptr, double TotalToDownload, double NowDownloaded, double TotalToUpload, double NowUploaded)
|
||||||
{
|
{
|
||||||
current_time = time_ms();
|
current_time = time_ms();
|
||||||
if (current_time - 50 > last_progress_timestamp) {
|
if (current_time - 50 > last_progress_timestamp) {
|
||||||
putchar('\r');
|
|
||||||
double percent_done = (NowDownloaded / TotalToDownload) * number_chars;
|
double percent_done = (NowDownloaded / TotalToDownload) * number_chars;
|
||||||
double percent_done_clone = percent_done;
|
double percent_done_clone = percent_done;
|
||||||
putchar('[');
|
putchar('[');
|
||||||
|
@ -81,6 +83,7 @@ int progress_func(void* ptr, double TotalToDownload, double NowDownloaded, doubl
|
||||||
putchar(']');
|
putchar(']');
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
std::cout << NowDownloaded / 1048576 << "MiB / " << TotalToDownload / 1048576 << "MiB ";
|
std::cout << NowDownloaded / 1048576 << "MiB / " << TotalToDownload / 1048576 << "MiB ";
|
||||||
|
putchar('\r');
|
||||||
last_progress_timestamp = time_ms();
|
last_progress_timestamp = time_ms();
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue