[pacman-dev] Show total progress bar
Hey folks, Message about the TotalDownload option from way back in November 07: http://archlinux.org/pipermail/pacman-dev/2007-November/009948.html Back then, I did not know how to draw two progress bars. Well, now I have figured it out (and it only took ten months, not bad). I have a really terrible patch right now which somewhat works. If everyone thinks that having two progress bars is a good thing, then I will make a better patch. I don't know if it is a good thing or not. The output is a bit overwhelming, but it is fun to look at. To see what having two bars would look like without having to apply the patch, try this python script: import sys import time print 'pacman [###-------] 25%' print 'total [##--------] 10%', sys.stdout.flush() time.sleep(1) sys.stdout.write('\033[A\033[K\n\033[K\r\033[A') print 'pacman [#########-] 90%' print 'total [#####-----] 50%', sys.stdout.flush() time.sleep(1) sys.stdout.write('\033[A\033[K\n\033[K\r\033[A') print 'pacman [##########] 100%' print 'gcc [##--------] 10%' print 'total [######----] 60%', sys.stdout.flush() time.sleep(1) sys.stdout.write('\033[A\033[K\n\033[K\r\033[A') print 'gcc [######----] 60%' print 'total [########--] 80%', sys.stdout.flush() time.sleep(1) sys.stdout.write('\033[A\033[K\n\033[K\r\033[A') print 'gcc [########--] 80%' print 'total [#########-] 90%', sys.stdout.flush() time.sleep(1) sys.stdout.write('\033[A\033[K\n\033[K\r\033[A') print 'gcc [##########] 100%' print 'total [##########] 100%'
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
2008/9/27 Nathan Jones <nathanj@insightbb.com>:
Hey folks,
Message about the TotalDownload option from way back in November 07: http://archlinux.org/pipermail/pacman-dev/2007-November/009948.html
Back then, I did not know how to draw two progress bars. Well, now I have figured it out (and it only took ten months, not bad). I have a really terrible patch right now which somewhat works. If everyone thinks that having two progress bars is a good thing, then I will make a better patch.
I don't know if it is a good thing or not. The output is a bit overwhelming, but it is fun to look at.
Looks nice. I wonder if it works in all terminals (including windows ones over ssh). -- Roman Kyrylych (Роман Кирилич)
participants (2)
-
Nathan Jones
-
Roman Kyrylych