From d8d82215561305cb7af0a33d7810cbb9cadb2cea Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Fri, 22 Dec 2006 07:11:20 +0000 Subject: 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. --- src/pacman/log.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/pacman/log.c') diff --git a/src/pacman/log.c b/src/pacman/log.c index 67b69324..7231545e 100644 --- a/src/pacman/log.c +++ b/src/pacman/log.c @@ -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); + len = strlen(str); + + 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); - - neednl = (str[strlen(str)-1] == 10) ? 0 : 1; } /* Check verbosity option and, if set, print the -- cgit v1.2.3