X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fcolor.c;h=a927e9a7f7df2110f281cecea91900155fff812a;hp=c5037245c23cd21282ed681595d6188abcbbb9d2;hb=00f34116b32751764d42f81159c292d850c74bac;hpb=84bc6d1930165b21919541b3b24294a9d99c3541 diff --git a/lib-ui/color.c b/lib-ui/color.c index c503724..a927e9a 100644 --- a/lib-ui/color.c +++ b/lib-ui/color.c @@ -7,12 +7,10 @@ * please see the file GPL in the top level source directory. */ -#include - -#include "curses.h" - +#include #include "pattern.h" #include "mutt.h" +#include "madtty.h" /* globals */ int *ColorQuote; @@ -35,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}, @@ -47,9 +42,7 @@ static struct mapping_t Colors[] = { {"red", COLOR_RED}, {"white", COLOR_WHITE}, {"yellow", COLOR_YELLOW}, -#if defined (HAVE_USE_DEFAULT_COLORS) {"default", COLOR_DEFAULT}, -#endif {0, 0} }; @@ -89,20 +82,15 @@ 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; - if (free_colors && tmp->fg != -1 && tmp->bg != -1) - mutt_free_color (tmp->fg, tmp->bg); - /* we should really use the container type for regular expressions. */ - regfree (&tmp->rx); pattern_list_wipe(&tmp->color_pattern); p_delete(&tmp->pattern); @@ -125,94 +113,6 @@ void ci_start_color (void) /* special meaning: toggle the relevant attribute */ ColorDefs[MT_COLOR_BOLD] = 0; ColorDefs[MT_COLOR_UNDERLINE] = 0; - - start_color (); -} - -int mutt_alloc_color (int fg, int bg) -{ - COLOR_LIST *p = ColorList; - int i; - - /* 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 (HAVE_USE_DEFAULT_COLORS) - if (fg == COLOR_DEFAULT) - fg = -1; - if (bg == COLOR_DEFAULT) - bg = -1; -#endif - - init_pair (i, fg, bg); - - 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--; - - 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; - } } static int @@ -308,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; } @@ -322,7 +222,7 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ last->next = tmp->next; else ColorIndexList = tmp->next; - mutt_free_color_line (&tmp, parse_uncolor); + mutt_free_color_line(&tmp); break; } } @@ -369,13 +269,12 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive, if (tmp) { 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); + } } tmp->pair = attr; } else { @@ -390,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 */ @@ -402,7 +301,7 @@ 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; @@ -410,7 +309,7 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive, if (fg != -1 && bg != -1) { tmp->fg = fg; tmp->bg = bg; - attr |= mutt_alloc_color (fg, bg); + attr |= madtty_color_pair(fg, bg); } tmp->pair = attr; *top = tmp; @@ -522,7 +421,7 @@ parse_attr_spec (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr, static int fgbgattr_to_color (int fg, int bg, int attr) { if (fg != -1 && bg != -1) - return attr | mutt_alloc_color (fg, bg); + return attr | madtty_color_pair(fg, bg); else return attr; } @@ -567,7 +466,6 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err, return 0; -#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) @@ -575,7 +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 */ if (object == MT_COLOR_HEADER) r = add_pattern (&ColorHdrList, buf->data, 0, fg, bg, attr, err, 0); @@ -608,10 +505,8 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err, else ColorDefs[object] = fgbgattr_to_color (fg, bg, attr); -#ifdef HAVE_BKGDSET if (object == MT_COLOR_NORMAL && !option (OPTNOCURSES) && has_colors ()) - BKGDSET (MT_COLOR_NORMAL); -#endif + BKGDSET(main_w, MT_COLOR_NORMAL); return (r); }