index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Simon Gomizelj <simongmzlj@gmail.com> | 2013-03-01 14:27:40 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2013-03-07 15:55:04 +1000 |
commit | c8c7a5137473770eb4b2d9d54495c2a39b32cbe3 (patch) | |
tree | 4582021cba970256c6fa4efeb0fe9e557e8a89ae | |
parent | ea42d03ea153a17edc792844c572f0d3d0803bd6 (diff) |
-rw-r--r-- | src/pacman/conf.c | 4 | ||||
-rw-r--r-- | src/pacman/conf.h | 9 | ||||
-rw-r--r-- | src/pacman/pacman.c | 15 |
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 218ffb46..dca6e3e1 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -436,6 +436,10 @@ static int _parse_options(const char *key, char *value, pm_printf(ALPM_LOG_DEBUG, "config: totaldownload\n"); } else if(strcmp(key, "CheckSpace") == 0) { config->checkspace = 1; + } else if(strcmp(key, "Color") == 0) { + if(config->color == PM_COLOR_UNSET) { + config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF; + } } 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 d85d11f2..6cabd33e 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -34,6 +34,7 @@ typedef struct __config_t { unsigned short print; unsigned short checkspace; unsigned short usesyslog; + unsigned short color; double deltaratio; char *arch; char *print_format; @@ -129,7 +130,8 @@ enum { OP_PRINTFORMAT, OP_GPGDIR, OP_DBONLY, - OP_FORCE + OP_FORCE, + OP_COLOR }; /* clean method */ @@ -145,6 +147,11 @@ enum { PKG_LOCALITY_FOREIGN = (1 << 1) }; +enum { + PM_COLOR_UNSET = 0, + PM_COLOR_OFF, + PM_COLOR_ON +}; /* global config variable */ extern config_t *config; diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 38b28e1f..bb8b439f 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -197,6 +197,7 @@ static void usage(int op, const char * const myname) addlist(_(" -v, --verbose be verbose\n")); addlist(_(" --arch <arch> set an alternate architecture\n")); addlist(_(" --cachedir <dir> set an alternate package cache location\n")); + addlist(_(" --color <when> colorize the output\n")); addlist(_(" --config <path> set an alternate configuration file\n")); addlist(_(" --debug display debug messages\n")); addlist(_(" --gpgdir <path> set an alternate home directory for GnuPG\n")); @@ -394,6 +395,19 @@ static int parsearg_global(int opt) check_optarg(); config->cachedirs = alpm_list_add(config->cachedirs, strdup(optarg)); break; + case OP_COLOR: + if(strcmp("never", optarg) == 0) { + config->color = PM_COLOR_OFF; + } else if(strcmp("auto", optarg) == 0) { + config->color = isatty(fileno(stdout)) ? PM_COLOR_ON : PM_COLOR_OFF; + } else if(strcmp("always", optarg) == 0) { + config->color = PM_COLOR_ON; + } else { + pm_printf(ALPM_LOG_ERROR, _("invalid agument '%s' for %s\n"), + optarg, "--color"); + return 1; + } + break; case OP_CONFIG: check_optarg(); if(config->configfile) { @@ -632,6 +646,7 @@ static int parseargs(int argc, char *argv[]) {"print-format", required_argument, 0, OP_PRINTFORMAT}, {"gpgdir", required_argument, 0, OP_GPGDIR}, {"dbonly", no_argument, 0, OP_DBONLY}, + {"color", required_argument, 0, OP_COLOR}, {0, 0, 0, 0} }; |