summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-08-24 21:55:56 -0500
committerDan McGee <dan@archlinux.org>2011-08-25 16:09:52 -0500
commit73fcf17041cf00e0b6c3082bd354b8eaab412dab (patch)
treeda0ee94c0fcc8a3825a3ac6ef51cc7688c6e3951
parent30cad47fb91dec0748551cb7d8607871b95785e5 (diff)
downloadpacman-73fcf17041cf00e0b6c3082bd354b8eaab412dab.tar.xz
Slight refresh of the download progress callback
This cleans up some of the mess we have here. * switch to long units for the download size * omit the .0 decimal part from the download rate * omit the almost always zero HH: from estimated time if eta_h == 0 * Display --:-- if eta_h > 99; formatting was screwed up before The net result of this is we usually have 1 more character to use for filename display. Before: extra 500.9K 1242.4K/s 00:00:00 [######################] 100% community-testing 947.0B 28.2M/s 00:00:00 [######################] 100% multilib 26.5K 405.1K/s 00:00:00 [######################] 100% community 450.6K 1238.3K/s 00:00:00 [######################] 100% After: extra 500.9 KiB 1118K/s 00:00 [######################] 100% community-testing 947.0 B 23M/s 00:00 [######################] 100% multilib 26.5 KiB 255K/s 00:00 [######################] 100% community 450.6 KiB 1211K/s 00:00 [######################] 100% Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/callback.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 5ee4e5af..63f7b559 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -521,9 +521,6 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
if(infolen < 50) {
infolen = 50;
}
- /* explanation of magic 28 number at the end */
- filenamelen = infolen - 28;
-
/* only use TotalDownload if enabled and we have a callback value */
if(config->totaldownload && list_total) {
/* sanity check */
@@ -630,6 +627,16 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
strcat(fname, ".sig");
}
}
+
+ /* 1 space + filenamelen + 1 space + 6 for size + 1 space + 3 for label +
+ * + 2 spaces + 4 for rate + 1 for label + 2 for /s + 1 space +
+ * 8 for eta, gives us the magic 26 */
+ filenamelen = infolen - 30;
+ /* see printf() code, we omit 'HH:' in these conditions */
+ if(eta_h == 0 || eta_h >= 100) {
+ filenamelen += 3;
+ }
+
/* In order to deal with characters from all locales, we have to worry
* about wide characters and their column widths. A lot of stuff is
* done here to figure out the actual number of screen columns used
@@ -657,13 +664,18 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
}
rate_human = humanize_size((off_t)rate, '\0', 0, &rate_label);
- xfered_human = humanize_size(xfered, '\0', 0, &xfered_label);
-
- /* 1 space + filenamelen + 1 space + 7 for size + 1 + 7 for rate + 2 for /s + 1 space + 8 for eta */
- /* TODO: if eta_h > 99, formatting gets all messed up */
- printf(" %ls%-*s %6.1f%s %#6.1f%s/s %02u:%02u:%02u", wcfname,
- padwid, "", xfered_human, xfered_label, rate_human, rate_label,
- eta_h, eta_m, eta_s);
+ xfered_human = humanize_size(xfered, '\0', 1, &xfered_label);
+
+ printf(" %ls%-*s ", wcfname, padwid, "");
+ printf("%6.1f %3s %4.f%s/s ",
+ xfered_human, xfered_label, rate_human, rate_label);
+ if(eta_h == 0) {
+ printf("%02u:%02u", eta_m, eta_s);
+ } else if(eta_h < 100) {
+ printf("%02u:%02u:%02u", eta_h, eta_m, eta_s);
+ } else {
+ printf("--:--");
+ }
free(fname);
free(wcfname);