pro: Show download progress in the terminal window if available :^)
This commit is contained in:
parent
29ab518003
commit
853d900ee8
Notes:
sideshowbarker
2024-07-19 05:55:53 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/853d900ee88
1 changed files with 5 additions and 2 deletions
|
@ -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(¤t_time, nullptr);
|
||||
timersub(¤t_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());
|
||||
|
|
Loading…
Add table
Reference in a new issue