pro: Show download progress in the terminal window if available :^)

This commit is contained in:
Andreas Kling 2020-05-30 22:17:46 +02:00
parent 29ab518003
commit 853d900ee8
Notes: sideshowbarker 2024-07-19 05:55:53 +09:00

View file

@ -60,10 +60,12 @@ int main(int argc, char** argv)
download->on_progress = [&](Optional<u32> maybe_total_size, u32 downloaded_size) {
fprintf(stderr, "\r\033[2K");
if (maybe_total_size.has_value())
if (maybe_total_size.has_value()) {
fprintf(stderr, "\033]9;%d;%d;\033\\", downloaded_size, maybe_total_size.value());
fprintf(stderr, "Download progress: %s / %s", human_readable_size(downloaded_size).characters(), human_readable_size(maybe_total_size.value()).characters());
else
} else {
fprintf(stderr, "Download progress: %s / ???", human_readable_size(downloaded_size).characters());
}
gettimeofday(&current_time, nullptr);
timersub(&current_time, &prev_time, &time_diff);
@ -77,6 +79,7 @@ int main(int argc, char** argv)
prev_time = current_time;
};
download->on_finish = [&](bool success, auto& payload, auto, auto&) {
fprintf(stderr, "\033]9;-1;\033\\");
fprintf(stderr, "\n");
if (success)
write(STDOUT_FILENO, payload.data(), payload.size());