Browse code

bb12431: Freshclam progress bar fixes

Disable line wrap when printing the progress bar so that small terminal
windows do not see excessive lines printed.
Reduce the number of characters in the progress bar to accomodate
80-char width terminals.
Correctly display number of kilobytes (KiB) in progress bar. Previously
was showing # of MiB but printing "KiB".

Micah Snyder authored on 2019/12/24 22:13:47
Showing 3 changed files
... ...
@@ -257,6 +257,7 @@ CLAMAV_PRIVATE {
257 257
     cl_base64_decode;
258 258
     cl_base64_encode;
259 259
     cli_sanitize_filepath;
260
+    cli_gentemp_with_prefix;
260 261
 
261 262
     __cli_strcasestr;
262 263
     __cli_strndup;
... ...
@@ -166,7 +166,7 @@ static void printBytes(curl_off_t bytes)
166 166
         double megabytes = bytes / (double)(1024 * 1024);
167 167
         fprintf(stdout, "%.02fMiB", megabytes);
168 168
     } else if (bytes / 1024 > 1) {
169
-        double kilobytes = bytes / (double)(1024 * 1024);
169
+        double kilobytes = bytes / (double)(1024);
170 170
         fprintf(stdout, "%.02fKiB", kilobytes);
171 171
     } else {
172 172
         fprintf(stdout, "%" CURL_FORMAT_CURL_OFF_T "B", bytes);
... ...
@@ -187,7 +187,7 @@ static int xferinfo(void *prog,
187 187
     TIMETYPE remtime               = 0;
188 188
 
189 189
     uint32_t i                = 0;
190
-    uint32_t totalNumDots     = 40;
190
+    uint32_t totalNumDots     = 30;
191 191
     uint32_t numDots          = 0;
192 192
     double fractiondownloaded = 0.0;
193 193
 
... ...
@@ -203,11 +203,14 @@ static int xferinfo(void *prog,
203 203
     xferProg->lastRunTime = curtime;
204 204
     remtime               = (curtime * 1 / fractiondownloaded) - curtime;
205 205
 
206
+#ifndef _WIN32
207
+    fprintf(stdout, "\e[?7l");
208
+#endif
206 209
 #ifdef TIME_IN_US
207 210
     if (fractiondownloaded <= 0.0) {
208 211
         fprintf(stdout, "Time: %.1fs ", curtime / 1000000.0);
209 212
     } else {
210
-        fprintf(stdout, "Time: %.1fs, ETA; %.1fs ", curtime / 1000000.0, remtime / 1000000.0);
213
+        fprintf(stdout, "Time: %.1fs, ETA: %.1fs ", curtime / 1000000.0, remtime / 1000000.0);
211 214
     }
212 215
 #else
213 216
     if (fractiondownloaded <= 0.0) {
... ...
@@ -244,11 +247,14 @@ static int xferinfo(void *prog,
244 244
     }
245 245
 
246 246
     if (NowDownloaded < TotalToDownload) {
247
-        fprintf(stdout, "  \r");
247
+        fprintf(stdout, "     \r");
248 248
     } else {
249
-        fprintf(stdout, "  \n");
249
+        fprintf(stdout, "     \n");
250 250
         xferProg->bComplete = 1;
251 251
     }
252
+#ifndef _WIN32
253
+    fprintf(stdout, "\e[?7h");
254
+#endif
252 255
     fflush(stdout);
253 256
 
254 257
     return 0;
... ...
@@ -186,6 +186,7 @@ EXPORTS __cli_strcasestr @44388 NONAME
186 186
 EXPORTS __cli_strndup @44389 NONAME
187 187
 EXPORTS __cli_strnlen @44390 NONAME
188 188
 EXPORTS __cli_strnstr @44391 NONAME
189
+EXPORTS cli_gentemp_with_prefix @44392 NONAME
189 190
 
190 191
 ; compatibility layer, tommath, zlib
191 192
 EXPORTS w32_srand @44269 NONAME