[pacman-dev] [PATCH 08/14] colourize warnings and errors

Allan McRae allan at archlinux.org
Wed Mar 6 10:48:42 EST 2013


From: Simon Gomizelj <simongmzlj at gmail.com>

Signed-off-by: Simon Gomizelj <simongmzlj at gmail.com>
---

Resending for review...

 src/pacman/conf.c | 12 +++++++-----
 src/pacman/conf.h |  2 ++
 src/pacman/util.c |  6 ++++--
 3 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index baaf6a1..f488234 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -61,12 +61,12 @@ config_t *config = NULL;
 
 void enable_colors(int colors)
 {
-	colstr_t *colstr = &config->colstr;
-
 	if(colors == PM_COLOR_ON) {
-		colstr->colon = BOLDBLUE "::" BOLDWHITE " ";
-		colstr->title = BOLDWHITE;
-		colstr->nc    = NC;
+		config->colstr.colon = BOLDBLUE "::" BOLDWHITE " ";
+		config->colstr.title = BOLDWHITE;
+		config->colstr.warn  = BOLDYELLOW;
+		config->colstr.err   = BOLDRED;
+		config->colstr.nc    = NC;
 	}
 }
 
@@ -93,6 +93,8 @@ config_t *config_new(void)
 
 	newconfig->colstr.colon = ":: ";
 	newconfig->colstr.title = "";
+	newconfig->colstr.warn  = "",
+	newconfig->colstr.err   = "",
 	newconfig->colstr.nc    = "";
 
 	return newconfig;
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index aab1832..18bfb02 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -25,6 +25,8 @@
 typedef struct __colstr_t {
 	const char *colon;
 	const char *title;
+	const char *warn;
+	const char *err;
 	const char *nc;
 } colstr_t;
 
diff --git a/src/pacman/util.c b/src/pacman/util.c
index d0e70ea..dcb0406 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -1661,10 +1661,12 @@ int pm_vfprintf(FILE *stream, alpm_loglevel_t level, const char *format, va_list
 	/* print a prefix to the message */
 	switch(level) {
 		case ALPM_LOG_ERROR:
-			fprintf(stream, _("error: "));
+			fprintf(stream, "%s%s%s", config->colstr.err, _("error: "),
+					config->colstr.nc);
 			break;
 		case ALPM_LOG_WARNING:
-			fprintf(stream, _("warning: "));
+			fprintf(stream, "%s%s%s", config->colstr.warn, _("warning: "),
+					config->colstr.nc);
 			break;
 		case ALPM_LOG_DEBUG:
 			fprintf(stream, "debug: ");
-- 
1.8.1.5



More information about the pacman-dev mailing list