[pacman-dev] [PATCH 07/15] introduce colstr for colourizing
Simon Gomizelj
simongmzlj at gmail.com
Wed Mar 6 12:51:48 EST 2013
colstr_t colstr will hold the colourizing agents.
Signed-off-by: Simon Gomizelj <simongmzlj at gmail.com>
---
src/pacman/conf.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
src/pacman/conf.h | 16 ++++++++++++++++
src/pacman/pacman.c | 1 +
3 files changed, 65 insertions(+)
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index dca6e3e..815df95 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -39,6 +39,43 @@
/* global config variable */
config_t *config = NULL;
+#define NOCOLOR "\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"
+
+void enable_colors(int colors)
+{
+ colstr_t *colstr = &config->colstr;
+
+ if(colors == PM_COLOR_ON) {
+ colstr->colon = BOLDBLUE "::" BOLDWHITE " ";
+ colstr->title = BOLDWHITE;
+ colstr->repo = BOLDMAGENTA;
+ colstr->version = BOLDGREEN;
+ colstr->groups = BOLDBLUE;
+ colstr->meta = BOLDCYAN;
+ colstr->warn = BOLDYELLOW;
+ colstr->err = BOLDRED;
+ colstr->nocolor = NOCOLOR;
+ }
+}
+
config_t *config_new(void)
{
config_t *newconfig = calloc(1, sizeof(config_t));
@@ -60,6 +97,16 @@ config_t *config_new(void)
newconfig->remotefilesiglevel = ALPM_SIG_USE_DEFAULT;
}
+ newconfig->colstr.colon = ":: ";
+ newconfig->colstr.title = "";
+ newconfig->colstr.repo = "";
+ newconfig->colstr.version = "";
+ newconfig->colstr.groups = "";
+ newconfig->colstr.meta = "";
+ newconfig->colstr.warn = "";
+ newconfig->colstr.err = "";
+ newconfig->colstr.nocolor = "";
+
return newconfig;
}
@@ -439,6 +486,7 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "Color") == 0) {
if(config->color == PM_COLOR_UNSET) {
config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF;
+ enable_colors(config->color);
}
} else {
pm_printf(ALPM_LOG_WARNING,
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 6cabd33..dcd3204 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -22,6 +22,18 @@
#include <alpm.h>
+typedef struct __colstr_t {
+ const char *colon;
+ const char *title;
+ const char *repo;
+ const char *version;
+ const char *groups;
+ const char *meta;
+ const char *warn;
+ const char *err;
+ const char *nocolor;
+} colstr_t;
+
typedef struct __config_t {
unsigned short op;
unsigned short quiet;
@@ -98,6 +110,9 @@ typedef struct __config_t {
alpm_list_t *explicit_adds;
alpm_list_t *explicit_removes;
+
+ /* Color strings for output */
+ colstr_t colstr;
} config_t;
/* Operations */
@@ -156,6 +171,7 @@ enum {
/* global config variable */
extern config_t *config;
+void enable_colors(int colors);
config_t *config_new(void);
int config_free(config_t *oldconfig);
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index bb8b439..a6ea14f 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -407,6 +407,7 @@ static int parsearg_global(int opt)
optarg, "--color");
return 1;
}
+ enable_colors(config->color);
break;
case OP_CONFIG:
check_optarg();
--
1.8.1.5
More information about the pacman-dev
mailing list