diff options
author | Chantry Xavier <shiningxc@gmail.com> | 2007-12-03 22:57:54 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-12-04 01:43:12 +0100 |
commit | 72dae726910bce78647fb47ccfbba657b229ffb4 (patch) | |
tree | f8cbb1007255f07f2d7fc47548d8175cd77f0288 /src/pacman/callback.c | |
parent | 0d1cb037566f3327315cf946d2443abb114b623a (diff) | |
download | pacman-72dae726910bce78647fb47ccfbba657b229ffb4.tar.gz pacman-72dae726910bce78647fb47ccfbba657b229ffb4.tar.xz |
Delay output during progress bar
This fixes the output issue related to the progress bar by delaying the
output. We can decide later (post-release) if we like this method or we want
to switch to something else.
Signed-off-by: Chantry Xavier <shiningxc@gmail.com>
[Dan: just some minor cleanups]
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman/callback.c')
-rw-r--r-- | src/pacman/callback.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 6129d8d7..3389ed85 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -45,8 +45,12 @@ static float rate_last; static int xfered_last; static struct timeval initial_time; -/* transaction progress bar ? */ -static int prevpercent=0; /* for less progressbar output */ +/* transaction progress bar */ +static int prevpercent = 0; /* for less progressbar output */ + +/* delayed output during progress bar */ +static int on_progress = 0; +static alpm_list_t *output = NULL; /* Silly little helper function, determines if the caller needs a visual update * since the last time this function was called. @@ -408,6 +412,20 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent, /* call refactored fill progress function */ fill_progress(percent, percent, getcols() - infolen); + + if(percent == 100) { + alpm_list_t *i = NULL; + on_progress = 0; + for(i = output; i; i = i->next) { + printf("%s", (char *)i->data); + } + fflush(stdout); + alpm_list_free_inner(output, free); + alpm_list_free(output); + output = NULL; + } else { + on_progress = 1; + } } /* callback to handle display of download progress */ @@ -546,7 +564,15 @@ void cb_log(pmloglevel_t level, char *fmt, va_list args) return; } - pm_vfprintf(stdout, level, fmt, args); + if(on_progress) { + char *string = NULL; + pm_vasprintf(&string, level, fmt, args); + if(string != NULL) { + output = alpm_list_add(output, string); + } + } else { + pm_vfprintf(stdout, level, fmt, args); + } } /* vim: set ts=2 sw=2 noet: */ |