index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Dan McGee <dan@archlinux.org> | 2011-08-24 21:55:56 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2011-08-25 16:09:52 -0500 |
commit | 73fcf17041cf00e0b6c3082bd354b8eaab412dab (patch) | |
tree | da0ee94c0fcc8a3825a3ac6ef51cc7688c6e3951 /src | |
parent | 30cad47fb91dec0748551cb7d8607871b95785e5 (diff) |
-rw-r--r-- | src/pacman/callback.c | 32 |
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); |