mirror of
https://github.com/moparisthebest/pacman
synced 2025-02-28 09:21:53 -05:00
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>
This commit is contained in:
parent
0d1cb03756
commit
72dae72691
@ -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: */
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user