diff options
author | Chantry Xavier <shiningxc@gmail.com> | 2007-12-03 22:57:54 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2007-12-03 18:43:12 -0600 |
commit | 72dae726910bce78647fb47ccfbba657b229ffb4 (patch) | |
tree | f8cbb1007255f07f2d7fc47548d8175cd77f0288 | |
parent | 0d1cb037566f3327315cf946d2443abb114b623a (diff) | |
download | 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>
-rw-r--r-- | src/pacman/callback.c | 32 | ||||
-rw-r--r-- | src/pacman/util.c | 35 | ||||
-rw-r--r-- | src/pacman/util.h | 1 |
3 files changed, 65 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: */ diff --git a/src/pacman/util.c b/src/pacman/util.c index 89313c83..d8bcb823 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -526,6 +526,41 @@ int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) return(ret); } +int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args) +{ + int ret = 0; + char *msg = NULL; + + /* if current logmask does not overlap with level, do not print msg */ + if(!(config->logmask & level)) { + return ret; + } + + /* print the message using va_arg list */ + ret = vasprintf(&msg, format, args); + + /* print a prefix to the message */ + switch(level) { + case PM_LOG_DEBUG: + asprintf(string, _("debug: %s"), msg); + break; + case PM_LOG_ERROR: + asprintf(string, _("error: %s"), msg); + break; + case PM_LOG_WARNING: + asprintf(string, _("warning: %s"), msg); + break; + case PM_LOG_FUNCTION: + asprintf(string, _("function: %s"), msg); + break; + default: + break; + } + free(msg); + + return(ret); +} + int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) { int ret = 0; diff --git a/src/pacman/util.h b/src/pacman/util.h index 0295d7e5..4f4b3db3 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -55,6 +55,7 @@ int yesno(char *fmt, ...); int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3))); int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4))); int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); +int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); #ifndef HAVE_STRNDUP char *strndup(const char *s, size_t n); |