summaryrefslogtreecommitdiffstats
path: root/src/pacman/log.c
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2006-12-22 08:11:20 +0100
committerAaron Griffin <aaron@archlinux.org>2006-12-22 08:11:20 +0100
commitd8d82215561305cb7af0a33d7810cbb9cadb2cea (patch)
treeee77b2e7867d524d6d23ee5e2a783ae8bf5bdb53 /src/pacman/log.c
parent796490546e2d3868a387ff18b05f2fa382a9aa7e (diff)
downloadpacman-d8d82215561305cb7af0a33d7810cbb9cadb2cea.tar.gz
pacman-d8d82215561305cb7af0a33d7810cbb9cadb2cea.tar.xz
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.
Diffstat (limited to 'src/pacman/log.c')
-rw-r--r--src/pacman/log.c32
1 files changed, 29 insertions, 3 deletions
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