summaryrefslogtreecommitdiff
path: root/src/pacman
diff options
context:
space:
mode:
authorSimon Gomizelj <simongmzlj@gmail.com>2013-03-01 14:52:16 -0500
committerAllan McRae <allan@archlinux.org>2013-03-07 15:55:04 +1000
commit6582f68c9d8c36806b2450540cf2dea87c930177 (patch)
tree083a30deef0c4d2ceba6e2dbd1e55dcdb8383e84 /src/pacman
parentc8c7a5137473770eb4b2d9d54495c2a39b32cbe3 (diff)
introduce colstr for colourizing
colstr_t colstr will hold the colourizing agents. Signed-off-by: Simon Gomizelj <simongmzlj@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/pacman')
-rw-r--r--src/pacman/conf.c48
-rw-r--r--src/pacman/conf.h16
-rw-r--r--src/pacman/pacman.c1
3 files changed, 65 insertions, 0 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index dca6e3e1..815df95f 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 6cabd33e..dcd32040 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 bb8b439f..a6ea14f7 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();