[pacman-dev] [PATCH] Show total progress bar.
Nathan Jones
nathanj at insightbb.com
Fri Sep 26 20:45:59 EDT 2008
This is a hack.
---
src/pacman/callback.c | 39 +++++++++++++++++++++++++++------------
1 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 59b4064..8a17111 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -86,8 +86,8 @@ static float get_update_timediff(int first_call)
}
/* refactored from cb_trans_progress */
-static void fill_progress(const int bar_percent, const int disp_percent,
- const int proglen)
+static void fill_progress(const int bar_percent,
+ const int proglen, const char *endline)
{
const unsigned int hashlen = proglen - 8;
const unsigned int hash = bar_percent * hashlen / 100;
@@ -139,16 +139,10 @@ static void fill_progress(const int bar_percent, const int disp_percent,
}
/* print percent after progress bar */
if(proglen > 5) {
- /* show total download percent if option is enabled */
- int p = config->totaldownload ? disp_percent : bar_percent;
- printf(" %3d%%", p);
+ printf(" %3d%%", bar_percent);
}
- if(bar_percent == 100) {
- printf("\n");
- } else {
- printf("\r");
- }
+ printf(endline);
fflush(stdout);
}
@@ -399,7 +393,7 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
free(wcstr);
/* call refactored fill progress function */
- fill_progress(percent, percent, getcols() - infolen);
+ fill_progress(percent, getcols() - infolen, percent == 100 ? "\n" : "\r");
if(percent == 100) {
alpm_list_t *i = NULL;
@@ -441,6 +435,8 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
int file_percent = 0, total_percent = 0;
char rate_size = 'K', xfered_size = 'K';
+ static int beenheredonethat = 0;
+
if(config->noprogressbar || file_total == -1) {
if(file_xfered == 0) {
printf(_("downloading %s...\n"), filename);
@@ -574,6 +570,18 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
}
}
+ /* move up if not the first time download progress is being displayed */
+ if (beenheredonethat == 1)
+ {
+ printf("\033[A" /* move up */
+ "\033[K\n" /* kill line */
+ "\033[K\r" /* kill line */
+ "\033[A" /* move up */
+ );
+ }
+ beenheredonethat = 1;
+
+
printf(" %ls%-*s %6.1f%c %#6.1f%c/s %02u:%02u:%02u", wcfname,
padwid, "", f_xfered, xfered_size,
rate, rate_size, eta_h, eta_m, eta_s);
@@ -581,7 +589,14 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
free(fname);
free(wcfname);
- fill_progress(file_percent, total_percent, getcols() - infolen);
+ fill_progress(file_percent, getcols() - infolen, "\n");
+
+ printf(" %-23s %6.1f%c %#6.1f%c/s %02u:%02u:%02u", "total",
+ f_xfered, xfered_size,
+ rate, rate_size, eta_h, eta_m, eta_s);
+ fill_progress(total_percent, getcols() - infolen, "\r");
+ if (file_percent == 100)
+ printf("\n");
return;
}
--
1.6.0
More information about the pacman-dev
mailing list