X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fcolor.c;h=a927e9a7f7df2110f281cecea91900155fff812a;hp=20fb8b0baee15eb8abec95bab0bd0a2f07da6853;hb=00f34116b32751764d42f81159c292d850c74bac;hpb=4a0b020a3048f079979bea43c04f9fe388f9354d diff --git a/lib-ui/color.c b/lib-ui/color.c index 20fb8b0..a927e9a 100644 --- a/lib-ui/color.c +++ b/lib-ui/color.c @@ -7,26 +7,10 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include "curses.h" - +#include +#include "pattern.h" #include "mutt.h" - -#include "lib/debug.h" - -#include -#include -#include +#include "madtty.h" /* globals */ int *ColorQuote; @@ -39,8 +23,6 @@ COLOR_LINE *ColorIndexList = NULL; /* local to this file */ static int ColorQuoteSize; -#ifdef HAVE_COLOR - #define COLOR_DEFAULT (-2) typedef struct color_list { @@ -51,9 +33,6 @@ typedef struct color_list { struct color_list *next; } COLOR_LIST; -static COLOR_LIST *ColorList = NULL; -static int UserColors = 0; - static struct mapping_t Colors[] = { {"black", COLOR_BLACK}, {"blue", COLOR_BLUE}, @@ -63,14 +42,10 @@ static struct mapping_t Colors[] = { {"red", COLOR_RED}, {"white", COLOR_WHITE}, {"yellow", COLOR_YELLOW}, -#if defined (USE_SLANG_CURSES) || defined (HAVE_USE_DEFAULT_COLORS) {"default", COLOR_DEFAULT}, -#endif {0, 0} }; -#endif /* HAVE_COLOR */ - static struct mapping_t Fields[] = { {"hdrdefault", MT_COLOR_HDEFAULT}, {"quoted", MT_COLOR_QUOTED}, @@ -107,26 +82,17 @@ static COLOR_LINE *mutt_new_color_line (void) return (p); } -static void mutt_free_color_line (COLOR_LINE ** l, int free_colors) +static void mutt_free_color_line(COLOR_LINE ** l) { COLOR_LINE *tmp; if (!l || !*l) return; - tmp = *l; -#ifdef HAVE_COLOR - if (free_colors && tmp->fg != -1 && tmp->bg != -1) - mutt_free_color (tmp->fg, tmp->bg); -#endif - - /* we should really introduce a container - * type for regular expressions. - */ - + /* we should really use the container type for regular expressions. */ regfree (&tmp->rx); - mutt_pattern_free (&tmp->color_pattern); + pattern_list_wipe(&tmp->color_pattern); p_delete(&tmp->pattern); p_delete(l); } @@ -147,153 +113,8 @@ void ci_start_color (void) /* special meaning: toggle the relevant attribute */ ColorDefs[MT_COLOR_BOLD] = 0; ColorDefs[MT_COLOR_UNDERLINE] = 0; - -#ifdef HAVE_COLOR - start_color (); -#endif } -#ifdef HAVE_COLOR - -#ifdef USE_SLANG_CURSES -static char *get_color_name (char *dest, size_t destlen, int val) -{ - static char *missing[3] = { "brown", "lightgray", "default" }; - int i; - - switch (val) { - case COLOR_YELLOW: - m_strcpy(dest, destlen, missing[0]); - return dest; - - case COLOR_WHITE: - m_strcpy(dest, destlen, missing[1]); - return dest; - - case COLOR_DEFAULT: - m_strcpy(dest, destlen, missing[2]); - return dest; - } - - for (i = 0; Colors[i].name; i++) { - if (Colors[i].value == val) { - m_strcpy(dest, destlen, Colors[i].name); - return dest; - } - } - - /* Sigh. If we got this far, the color is of the form 'colorN' - * Slang can handle this itself, so just return 'colorN' - */ - - snprintf (dest, destlen, "color%d", val); - return dest; -} -#endif - -int mutt_alloc_color (int fg, int bg) -{ - COLOR_LIST *p = ColorList; - int i; - -#if defined (USE_SLANG_CURSES) - char fgc[SHORT_STRING], bgc[SHORT_STRING]; -#endif - - /* check to see if this color is already allocated to save space */ - while (p) { - if (p->fg == fg && p->bg == bg) { - (p->count)++; - return (COLOR_PAIR (p->index)); - } - p = p->next; - } - - /* check to see if there are colors left */ - if (++UserColors > COLOR_PAIRS) - return (A_NORMAL); - - /* find the smallest available index (object) */ - i = 1; - for (;;) { - p = ColorList; - while (p) { - if (p->index == i) - break; - p = p->next; - } - if (p == NULL) - break; - i++; - } - - p = p_new(COLOR_LIST, 1); - p->next = ColorList; - ColorList = p; - - p->index = i; - p->count = 1; - p->bg = bg; - p->fg = fg; - -#if defined (USE_SLANG_CURSES) - if (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT) - SLtt_set_color (i, NULL, get_color_name (fgc, sizeof (fgc), fg), - get_color_name (bgc, sizeof (bgc), bg)); - else -#elif defined (HAVE_USE_DEFAULT_COLORS) - if (fg == COLOR_DEFAULT) - fg = -1; - if (bg == COLOR_DEFAULT) - bg = -1; -#endif - - init_pair (i, fg, bg); - - debug_print (1, ("Color pairs used so far: %d\n", UserColors)); - - return (COLOR_PAIR (p->index)); -} - -void mutt_free_color (int fg, int bg) -{ - COLOR_LIST *p, *q; - - p = ColorList; - while (p) { - if (p->fg == fg && p->bg == bg) { - (p->count)--; - if (p->count > 0) - return; - - UserColors--; - debug_print (1, ("Color pairs used so far: %d\n", UserColors)); - - if (p == ColorList) { - ColorList = ColorList->next; - p_delete(&p); - return; - } - q = ColorList; - while (q) { - if (q->next == p) { - q->next = p->next; - p_delete(&p); - return; - } - q = q->next; - } - /* can't get here */ - } - p = p->next; - } -} - -#endif /* HAVE_COLOR */ - - -#ifdef HAVE_COLOR - static int parse_color_name (const char *s, int *col, int *attr, int brite, BUFFER * err) { @@ -323,9 +144,6 @@ parse_color_name (const char *s, int *col, int *attr, int brite, BUFFER * err) return 0; } -#endif - - /* usage: uncolor index pattern [pattern...] * unmono index pattern [pattern...] */ @@ -334,17 +152,12 @@ static int _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data, BUFFER * err, short parse_uncolor); - -#ifdef HAVE_COLOR - int mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data, BUFFER * err) { return _mutt_parse_uncolor (buf, s, data, err, 1); } -#endif - int mutt_parse_unmono (BUFFER * buf, BUFFER * s, unsigned long data, BUFFER * err) { @@ -379,28 +192,14 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ return (-1); } - if ( -#ifdef HAVE_COLOR - /* we're running without curses */ - option (OPTNOCURSES) - || /* we're parsing an uncolor command, and have no colors */ - (parse_uncolor && !has_colors ()) - /* we're parsing an unmono command, and have colors */ - || (!parse_uncolor && has_colors ()) -#else - /* We don't even have colors compiled in */ - parse_uncolor -#endif - ) { + if (option (OPTNOCURSES) || (parse_uncolor != has_colors())) { /* just eat the command, but don't do anything real about it */ - do + do { mutt_extract_token (buf, s, 0); - while (MoreArgs (s)); - + } while (MoreArgs(s)); return 0; } - do { mutt_extract_token (buf, s, 0); if (!m_strcmp("*", buf->data)) { @@ -409,7 +208,7 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ do_cache = 1; last = tmp; tmp = tmp->next; - mutt_free_color_line (&last, parse_uncolor); + mutt_free_color_line(&last); } ColorIndexList = NULL; } @@ -419,12 +218,11 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ if (!m_strcmp(buf->data, tmp->pattern)) { if (!do_cache) do_cache = 1; - debug_print (1, ("Freeing pattern \"%s\" from ColorIndexList\n", tmp->pattern)); if (last) last->next = tmp->next; else ColorIndexList = tmp->next; - mutt_free_color_line (&tmp, parse_uncolor); + mutt_free_color_line(&tmp); break; } } @@ -469,21 +267,17 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive, } if (tmp) { -#ifdef HAVE_COLOR if (fg != -1 && bg != -1) { if (tmp->fg != fg || tmp->bg != bg) { - mutt_free_color (tmp->fg, tmp->bg); tmp->fg = fg; tmp->bg = bg; - attr |= mutt_alloc_color (fg, bg); - } - else + attr |= madtty_color_pair(fg, bg); + } else { attr |= (tmp->pair & ~A_BOLD); + } } -#endif /* HAVE_COLOR */ tmp->pair = attr; - } - else { + } else { int r; char buf[STRING]; @@ -495,7 +289,7 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive, mutt_check_simple (buf, sizeof (buf), NONULL (SimpleSearch)); if ((tmp->color_pattern = mutt_pattern_comp (buf, M_FULL_MSG, err)) == NULL) { - mutt_free_color_line (&tmp, 1); + mutt_free_color_line(&tmp); return -1; } /* force re-caching of index colors */ @@ -507,18 +301,16 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive, REGCOMP (&tmp->rx, s, (sensitive ? mutt_which_case (s) : REG_ICASE))) != 0) { regerror (r, &tmp->rx, err->data, err->dsize); - mutt_free_color_line (&tmp, 1); + mutt_free_color_line(&tmp); return (-1); } tmp->next = *top; tmp->pattern = m_strdup(s); -#ifdef HAVE_COLOR if (fg != -1 && bg != -1) { tmp->fg = fg; tmp->bg = bg; - attr |= mutt_alloc_color (fg, bg); + attr |= madtty_color_pair(fg, bg); } -#endif tmp->pair = attr; *top = tmp; } @@ -562,8 +354,6 @@ parse_object (BUFFER * buf, BUFFER * s, int *o, int *ql, BUFFER * err) typedef int (*parser_callback_t) (BUFFER *, BUFFER *, int *, int *, int *, BUFFER *); -#ifdef HAVE_COLOR - static int parse_color_pair (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr, BUFFER * err) @@ -591,8 +381,6 @@ parse_color_pair (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr, return 0; } -#endif - static int parse_attr_spec (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr, BUFFER * err) @@ -632,11 +420,9 @@ parse_attr_spec (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr, static int fgbgattr_to_color (int fg, int bg, int attr) { -#ifdef HAVE_COLOR if (fg != -1 && bg != -1) - return attr | mutt_alloc_color (fg, bg); + return attr | madtty_color_pair(fg, bg); else -#endif return attr; } @@ -680,8 +466,6 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err, return 0; -#ifdef HAVE_COLOR -# ifdef HAVE_USE_DEFAULT_COLORS if (!option (OPTNOCURSES) && has_colors () /* delay use_default_colors() until needed, since it initializes things */ && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT) @@ -689,8 +473,6 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err, m_strcpy(err->data, err->dsize, _("default colors not supported")); return (-1); } -# endif /* HAVE_USE_DEFAULT_COLORS */ -#endif if (object == MT_COLOR_HEADER) r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err, 0); @@ -723,18 +505,12 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err, else ColorDefs[object] = fgbgattr_to_color (fg, bg, attr); -#ifdef HAVE_COLOR -# ifdef HAVE_BKGDSET if (object == MT_COLOR_NORMAL && !option (OPTNOCURSES) && has_colors ()) - BKGDSET (MT_COLOR_NORMAL); -# endif -#endif + BKGDSET(main_w, MT_COLOR_NORMAL); return (r); } -#ifdef HAVE_COLOR - int mutt_parse_color (BUFFER * buff, BUFFER * s, unsigned long data __attribute__ ((unused)), BUFFER * err) { @@ -746,20 +522,13 @@ int mutt_parse_color (BUFFER * buff, BUFFER * s, unsigned long data __attribute_ return _mutt_parse_color (buff, s, err, parse_color_pair, dry_run); } -#endif - int mutt_parse_mono (BUFFER * buff, BUFFER * s, unsigned long data __attribute__ ((unused)), BUFFER * err) { int dry_run = 0; -#ifdef HAVE_COLOR if (option (OPTNOCURSES) || has_colors ()) dry_run = 1; -#else - if (option (OPTNOCURSES)) - dry_run = 1; -#endif return _mutt_parse_color (buff, s, err, parse_attr_spec, dry_run); }