mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:57:47 +00:00
pro: Show download progress in the terminal window if available :^)
This commit is contained in:
parent
29ab518003
commit
853d900ee8
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) {
|
download->on_progress = [&](Optional<u32> maybe_total_size, u32 downloaded_size) {
|
||||||
fprintf(stderr, "\r\033[2K");
|
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());
|
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());
|
fprintf(stderr, "Download progress: %s / ???", human_readable_size(downloaded_size).characters());
|
||||||
|
}
|
||||||
|
|
||||||
gettimeofday(¤t_time, nullptr);
|
gettimeofday(¤t_time, nullptr);
|
||||||
timersub(¤t_time, &prev_time, &time_diff);
|
timersub(¤t_time, &prev_time, &time_diff);
|
||||||
|
@ -77,6 +79,7 @@ int main(int argc, char** argv)
|
||||||
prev_time = current_time;
|
prev_time = current_time;
|
||||||
};
|
};
|
||||||
download->on_finish = [&](bool success, auto& payload, auto, auto&) {
|
download->on_finish = [&](bool success, auto& payload, auto, auto&) {
|
||||||
|
fprintf(stderr, "\033]9;-1;\033\\");
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
if (success)
|
if (success)
|
||||||
write(STDOUT_FILENO, payload.data(), payload.size());
|
write(STDOUT_FILENO, payload.data(), payload.size());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue