From 72dae726910bce78647fb47ccfbba657b229ffb4 Mon Sep 17 00:00:00 2001 From: Chantry Xavier Date: Mon, 3 Dec 2007 22:57:54 +0100 Subject: 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 [Dan: just some minor cleanups] Signed-off-by: Dan McGee --- src/pacman/callback.c | 32 +++++++++++++++++++++++++++++--- src/pacman/util.c | 35 +++++++++++++++++++++++++++++++++++ src/pacman/util.h | 1 + 3 files changed, 65 insertions(+), 3 deletions(-) (limited to 'src') 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); -- cgit v1.2.3-24-g4f1b