[pacman-dev] [PATCH 1/2] Add a few more sizes to humanize_sizes()
Because why the hell not? Exbibyte, zebibyte, and yobibyte are going in, even though nothing bigger than the 2^60 exbibyte can be represented using an off_t variable anyway. Signed-off-by: Dan McGee <dan@archlinux.org> --- src/pacman/util.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index 585f402..995b275 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -917,8 +917,10 @@ static char *pkg_get_location(alpm_pkg_t *pkg) double humanize_size(off_t bytes, const char target_unit, int long_labels, const char **label) { - static const char *shortlabels[] = {"B", "K", "M", "G", "T", "P"}; - static const char *longlabels[] = {"B", "KiB", "MiB", "GiB", "TiB", "PiB"}; + static const char *shortlabels[] = {"B", "K", "M", "G", + "T", "P", "E", "Z", "Y"}; + static const char *longlabels[] = {"B", "KiB", "MiB", "GiB", + "TiB", "PiB", "EiB", "ZiB", "YiB"}; static const int unitcount = sizeof(shortlabels) / sizeof(shortlabels[0]); const char **labels = long_labels ? longlabels : shortlabels; -- 1.7.6
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> --- src/pacman/callback.c | 32 ++++++++++++++++++++++---------- 1 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 5ee4e5a..63f7b55 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); -- 1.7.6
participants (1)
-
Dan McGee