On 07/03/13 01:39, Allan McRae wrote:
> From: Simon Gomizelj <[email protected]>
> 
> colstr_t colstr will hold the colourizing agents.
> 
> Signed-off-by: Simon Gomizelj <[email protected]>
> ---
> 
> Sending for easy review...
> 
>  src/pacman/conf.c   | 36 ++++++++++++++++++++++++++++++++++++
>  src/pacman/conf.h   | 10 ++++++++++
>  src/pacman/pacman.c |  1 +
>  src/pacman/util.c   |  6 ++++--
>  4 files changed, 51 insertions(+), 2 deletions(-)
> 
> diff --git a/src/pacman/conf.c b/src/pacman/conf.c
> index dca6e3e..baaf6a1 100644
> --- a/src/pacman/conf.c
> +++ b/src/pacman/conf.c
> @@ -39,6 +39,37 @@
>  /* global config variable */
>  config_t *config = NULL;
>  
> +#define NC            "\033[0m"

Can this get a decent name?  NOCOLOR  And usage of "nc" throughout.

> +
> +#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->nc    = NC;
> +     }
> +}
> +
>  config_t *config_new(void)
>  {
>       config_t *newconfig = calloc(1, sizeof(config_t));
> @@ -60,6 +91,10 @@ config_t *config_new(void)
>               newconfig->remotefilesiglevel = ALPM_SIG_USE_DEFAULT;
>       }
>  
> +     newconfig->colstr.colon = ":: ";
> +     newconfig->colstr.title = "";
> +     newconfig->colstr.nc    = "";
> +
>       return newconfig;
>  }
>  
> @@ -439,6 +474,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..aab1832 100644
> --- a/src/pacman/conf.h
> +++ b/src/pacman/conf.h
> @@ -22,6 +22,12 @@
>  
>  #include <alpm.h>
>  
> +typedef struct __colstr_t {
> +     const char *colon;
> +     const char *title;
> +     const char *nc;
> +} colstr_t;
> +
>  typedef struct __config_t {
>       unsigned short op;
>       unsigned short quiet;
> @@ -98,6 +104,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 +165,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 aabdba0..6d624d2 100644
> --- a/src/pacman/pacman.c
> +++ b/src/pacman/pacman.c
> @@ -407,6 +407,7 @@ static int parsearg_global(int opt)
>                                               optarg);
>                               return 1;
>                       }
> +                     enable_colors(config->color);
>                       break;
>               case OP_CONFIG:
>                       check_optarg();


Everything below here looks out of place - it was in a separate patch
previously.  Also, note comment below.

> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 3027789..d0e70ea 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -1491,7 +1491,7 @@ static int question(short preset, const char *format, 
> va_list args)
>       fflush(stdout);
>       fflush(stderr);
>  
> -     fprintf(stream, ":: ");
> +     fputs(config->colstr.colon, stream);
>       vfprintf(stream, format, args);

When you move this to a separate patch, merge in:

[PATCH 10/14] have question properly reset itself

>       if(preset) {
> @@ -1558,11 +1558,13 @@ int colon_printf(const char *fmt, ...)
>       int ret;
>       va_list args;
>  
> -     fputs(":: ", stdout);
>       va_start(args, fmt);
> +     fputs(config->colstr.colon, stdout);
>       ret = vprintf(fmt, args);
> +     fputs(config->colstr.nc, stdout);
>       va_end(args);
>  
> +     fflush(stdout);
>       return ret;
>  }
>  
> 


Reply via email to