[pacman-dev] [PATCH 07/16] introduce colstr for colourizing
Simon Gomizelj
simongmzlj at gmail.com
Fri Mar 1 16:32:36 EST 2013
colstr_t colstr will hold the colourizing agents.
Signed-off-by: Simon Gomizelj <simongmzlj at gmail.com>
---
src/pacman/conf.c | 36 ++++++++++++++++++++++++++++++++++++
src/pacman/conf.h | 7 +++++++
2 files changed, 43 insertions(+)
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index dca6e3e..34b4199 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -38,6 +38,40 @@
/* global config variable */
config_t *config = NULL;
+colstr_t colstr;
+
+#define NC "\033[0m"
+
+#define BLACK "\033[0;30m"
+#define RED "\033[0;31m"
+#define GREEN "\033[0;32m"
+#define YELLOW "\033[0;33m"
+#define BLUE "\033[0;34m"
+#define MAGENTA "\033[0;35m"
+#define CYAN "\033[0;36m"
+#define WHITE "\033[0;37m"
+
+#define BOLDBLACK "\033[1;30m"
+#define BOLDRED "\033[1;31m"
+#define BOLDGREEN "\033[1;32m"
+#define BOLDYELLOW "\033[1;33m"
+#define BOLDBLUE "\033[1;34m"
+#define BOLDMAGENTA "\033[1;35m"
+#define BOLDCYAN "\033[1;36m"
+#define BOLDWHITE "\033[1;37m"
+
+static void init_colors(int colors)
+{
+ if(colors == PM_COLOR_ON) {
+ colstr.colon = BOLDBLUE "::" BOLDWHITE;
+ colstr.title = BOLDWHITE;
+ colstr.nc = NC;
+ } else {
+ colstr.colon = "::";
+ colstr.title = "";
+ colstr.nc = "";
+ }
+}
config_t *config_new(void)
{
@@ -60,6 +94,7 @@ config_t *config_new(void)
newconfig->remotefilesiglevel = ALPM_SIG_USE_DEFAULT;
}
+ init_colors(PM_COLOR_OFF);
return newconfig;
}
@@ -440,6 +475,7 @@ static int _parse_options(const char *key, char *value,
if(config->color == PM_COLOR_UNSET) {
config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF;
}
+ init_colors(config->color);
} else {
pm_printf(ALPM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 6cabd33..9207c6d 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -100,6 +100,12 @@ typedef struct __config_t {
alpm_list_t *explicit_removes;
} config_t;
+typedef struct __colstr_t {
+ const char *colon;
+ const char *title;
+ const char *nc;
+} colstr_t;
+
/* Operations */
enum {
PM_OP_MAIN = 1,
@@ -155,6 +161,7 @@ enum {
/* global config variable */
extern config_t *config;
+extern colstr_t colstr;
config_t *config_new(void);
int config_free(config_t *oldconfig);
--
1.8.1.4
More information about the pacman-dev
mailing list