From 24288734e78aa2242b86dde8c770278fa1f5e05c Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Fri, 18 Dec 2020 21:38:18 +0100 Subject: add stderr checks, print carriage return when done downloading - no reason to print out a progress bar when outputting to a descriptor - control over the current line is given back so whatever downloaded something can print whatever it wants on that line --- src/net.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/net.c b/src/net.c index cf0dfdf..e7397f6 100644 --- a/src/net.c +++ b/src/net.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -48,15 +49,20 @@ static int xferinfo(void *p, curl_off_t dltotal, curl_off_t dlnow, UNUSED curl_o fprintf(stderr, "\rProgress: %3" CURL_FORMAT_CURL_OFF_T "%%", progress); + if (progress == 100) fprintf(stderr, "\r"); + return 0; } -struct MemoryStruct* downloadToRam(const char* URL, long progress) +struct MemoryStruct* downloadToRam(const char* URL, long noprogress) { CURL* curl_handle; CURLcode res = CURLE_OK; struct progress prog; + if (!isatty(STDERR_FILENO)) + noprogress = 1L; + struct MemoryStruct* chunk = malloc(sizeof(struct MemoryStruct)); if (chunk) @@ -75,7 +81,7 @@ struct MemoryStruct* downloadToRam(const char* URL, long progress) curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl_handle, CURLOPT_XFERINFOFUNCTION, xferinfo); curl_easy_setopt(curl_handle, CURLOPT_XFERINFODATA, &prog); - curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, progress); + curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, noprogress); res = curl_easy_perform(curl_handle); -- cgit v1.2.3