mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
Modified front end output routines to accept a "padding' setting, which pads any
statement with ' ' until the size of the terminal. The rationale is that, when a log message is emitted during progress bar display, the terminal is artifacted. This prevents that messiness.
This commit is contained in:
parent
796490546e
commit
d8d8221556
@ -65,6 +65,7 @@ void log_progress(const char *filename, int xfered, int total)
|
||||
float total_timediff, timediff;
|
||||
|
||||
if(xfered == 0) {
|
||||
set_output_padding(1); /* we need padding from pm_fprintf output */
|
||||
gettimeofday(&initial_time, NULL);
|
||||
gettimeofday(&last_time, NULL);
|
||||
xfered_last = 0;
|
||||
@ -88,6 +89,7 @@ void log_progress(const char *filename, int xfered, int total)
|
||||
/* compute final values */
|
||||
rate = total / (total_timediff * 1024);
|
||||
eta_s = (int)total_timediff;
|
||||
set_output_padding(0); /* shut off padding */
|
||||
} else if(timediff < UPDATE_SPEED_SEC) {
|
||||
/* we avoid computing the ETA on too small periods of time, so that
|
||||
results are more significant */
|
||||
|
@ -38,7 +38,14 @@
|
||||
|
||||
extern config_t *config;
|
||||
|
||||
int neednl; /* for cleaner message output */
|
||||
int neednl = 0; /* for cleaner message output */
|
||||
int needpad = 0; /* pad blanks to terminal width */
|
||||
|
||||
/* simple helper for needpad */
|
||||
void set_output_padding(int on)
|
||||
{
|
||||
needpad = on;
|
||||
}
|
||||
|
||||
/* Callback to handle notifications from the library
|
||||
*/
|
||||
@ -103,6 +110,7 @@ void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
|
||||
va_list args;
|
||||
|
||||
char str[LOG_STR_LEN];
|
||||
int len = 0;
|
||||
|
||||
if(neednl == 1 && line == NL) {
|
||||
fprintf(file, "\n");
|
||||
@ -113,10 +121,28 @@ void pm_fprintf(FILE *file, unsigned short line, char *fmt, ...)
|
||||
vsnprintf(str, LOG_STR_LEN, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
fprintf(file, str);
|
||||
fflush(file);
|
||||
len = strlen(str);
|
||||
|
||||
neednl = (str[strlen(str)-1] == 10) ? 0 : 1;
|
||||
if(needpad == 1 && str[len-1] == '\n') {
|
||||
/* we want this removed so we can pad */
|
||||
str[len-1] = ' ';
|
||||
neednl = 1;
|
||||
}
|
||||
|
||||
fprintf(file, str);
|
||||
if(needpad == 1) {
|
||||
unsigned int cols = getcols();
|
||||
for(int i=len; i < cols; ++i) {
|
||||
fprintf(file, " ");
|
||||
}
|
||||
if(neednl == 1) {
|
||||
fprintf(file, "\n");
|
||||
neednl = 0;
|
||||
} else {
|
||||
neednl = 1;
|
||||
}
|
||||
}
|
||||
fflush(file);
|
||||
}
|
||||
|
||||
/* Check verbosity option and, if set, print the
|
||||
|
@ -36,6 +36,8 @@ enum {
|
||||
CL /* current line */
|
||||
};
|
||||
|
||||
void set_output_padding(int on);
|
||||
|
||||
/* callback to handle messages/notifications from pacman library */
|
||||
void cb_log(unsigned short level, char *msg);
|
||||
|
||||
|
@ -295,6 +295,12 @@ void cb_trans_progress(unsigned char event, char *pkgname, int percent, int howm
|
||||
return;
|
||||
}
|
||||
|
||||
if(percent == 0) {
|
||||
set_output_padding(1); /* turn on output padding with ' ' */
|
||||
} else if(percent == 100) {
|
||||
set_output_padding(0); /* shut it off again */
|
||||
}
|
||||
|
||||
if (!pkgname)
|
||||
return;
|
||||
if (percent > 100)
|
||||
|
Loading…
Reference in New Issue
Block a user