> > -static void print_enriched_string (int attr, unsigned char *s, int 
> > do_color)
> > +static void print_enriched_string (int base_color, unsigned char *s, int 
> > do_color, int is_current)
> 
> I don't like the parameter to be named is_current but doesn't reflect that
> fact in the callers.

I agree. At first I just wanted to reduce the amount of option
handling and branching in print_enriched_string, but wasn't able to
get rid of it completely.

Now that you mention it, I've realized that do_color parameter isn't
used properly as well. print_enriched_string can always do its own
coloring without relying on indicator being applied already. The only
bit of information it needs is whether to use indicator on top of base
colors.

To further simplify option checking I've moved OPTCURSOROVERLAY check
into mutt_merge_colors. Given that we sometimes need to overlay more
than two colors and use merged result, I'm not sure what is the right
place for this check. I think it'll be better to keep it contained in
one or two functions. If this doesn't look right, the check can be
moved into print_enriched_string as in my previous version or a small
helper function can be created for combining three colors as you did
with mutt_attrset_cursor. What would be a better way to handle this?


diff --git a/color.c b/color.c
index cee39905..fb5c3aec 100644
--- a/color.c
+++ b/color.c
@@ -246,6 +246,9 @@ int mutt_merge_colors (int source_pair, int overlay_pair)
   COLOR_LIST *source, *overlay;
   int merged_pair, merged_fg, merged_bg;
 
+  if (!option (OPTCURSOROVERLAY))
+    return overlay_pair;
+
   merged_pair = overlay_pair;
 
   overlay = mutt_find_color_by_pair (overlay_pair & A_COLOR);
@@ -268,10 +271,7 @@ int mutt_merge_colors (int source_pair, int overlay_pair)
 
 void mutt_attrset_cursor (int source_pair, int cursor_pair)
 {
-  int merged_pair = cursor_pair;
-
-  if (option (OPTCURSOROVERLAY))
-    merged_pair = mutt_merge_colors (source_pair, cursor_pair);
+  int merged_pair = mutt_merge_colors (source_pair, cursor_pair);
 
   ATTRSET (merged_pair);
 }
diff --git a/menu.c b/menu.c
index 2da07c25..c7fa51f4 100644
--- a/menu.c
+++ b/menu.c
@@ -35,20 +35,26 @@ static size_t MenuStackCount = 0;
 static size_t MenuStackLen = 0;
 static MUTTMENU **MenuStack = NULL;
 
-static void print_enriched_string (int attr, unsigned char *s, int do_color)
+static void print_enriched_string (int base_color, unsigned char *s, int 
use_indicator)
 {
   wchar_t wc;
   size_t k;
   size_t n = mutt_strlen ((char *)s);
   mbstate_t mbstate;
 
+  int tree_color = mutt_merge_colors (base_color, ColorDefs[MT_COLOR_TREE]);
+  if (use_indicator)
+  {
+    tree_color = mutt_merge_colors (tree_color, ColorDefs[MT_COLOR_INDICATOR]);
+    base_color = mutt_merge_colors (base_color, ColorDefs[MT_COLOR_INDICATOR]);
+  }
+
   memset (&mbstate, 0, sizeof (mbstate));
   while (*s)
   {
     if (*s < MUTT_TREE_MAX)
     {
-      if (do_color)
-       SETCOLOR (MT_COLOR_TREE);
+      ATTRSET (tree_color);
       while (*s && *s < MUTT_TREE_MAX)
       {
        switch (*s)
@@ -165,7 +171,7 @@ static void print_enriched_string (int attr, unsigned char 
*s, int do_color)
        }
        s++, n--;
       }
-      if (do_color) ATTRSET(attr);
+      ATTRSET(base_color);
     }
     else if ((k = mbrtowc (&wc, (char *)s, n, &mbstate)) > 0)
     {
@@ -251,7 +257,6 @@ void menu_redraw_index (MUTTMENU *menu)
 {
   char buf[LONG_STRING];
   int i;
-  int do_color;
   int attr;
 
   for (i = menu->top; i < menu->top + menu->pagelen; i++)
@@ -265,24 +270,31 @@ void menu_redraw_index (MUTTMENU *menu)
 
       ATTRSET(attr);
       mutt_window_move (menu->indexwin, i - menu->top + menu->offset, 0);
-      do_color = 1;
 
       if (i == menu->current)
       {
-        mutt_attrset_cursor (attr, ColorDefs[MT_COLOR_INDICATOR]);
         if (option(OPTARROWCURSOR))
         {
+          SETCOLOR(MT_COLOR_INDICATOR);
           addstr ("->");
           ATTRSET(attr);
           addch (' ');
+          print_enriched_string (attr, (unsigned char *) buf, 0);
         }
         else
-          do_color = 0;
+        {
+          mutt_attrset_cursor (attr, ColorDefs[MT_COLOR_INDICATOR]);
+          print_enriched_string (attr, (unsigned char *) buf, 1);
+        }
+      }
+      else
+      {
+        if (option(OPTARROWCURSOR))
+        {
+          addstr("   ");
+        }
+        print_enriched_string (attr, (unsigned char *) buf, 0);
       }
-      else if (option(OPTARROWCURSOR))
-       addstr("   ");
-
-      print_enriched_string (attr, (unsigned char *) buf, do_color);
     }
     else
     {
@@ -325,11 +337,11 @@ void menu_redraw_motion (MUTTMENU *menu)
       menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
       menu_pad_string (menu, buf, sizeof (buf));
       mutt_window_move (menu->indexwin, menu->oldcurrent + menu->offset - 
menu->top, 3);
-      print_enriched_string (old_color, (unsigned char *) buf, 1);
+      print_enriched_string (old_color, (unsigned char *) buf, 0);
     }
 
     /* now draw it in the new location */
-    mutt_attrset_cursor (cur_color, ColorDefs[MT_COLOR_INDICATOR]);
+    SETCOLOR(MT_COLOR_INDICATOR);
     mutt_window_mvaddstr (menu->indexwin, menu->current + menu->offset - 
menu->top, 0, "->");
   }
   else
@@ -337,14 +349,14 @@ void menu_redraw_motion (MUTTMENU *menu)
     /* erase the current indicator */
     menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent);
     menu_pad_string (menu, buf, sizeof (buf));
-    print_enriched_string (old_color, (unsigned char *) buf, 1);
+    print_enriched_string (old_color, (unsigned char *) buf, 0);
 
     /* now draw the new one to reflect the change */
     menu_make_entry (buf, sizeof (buf), menu, menu->current);
     menu_pad_string (menu, buf, sizeof (buf));
     mutt_attrset_cursor (cur_color, ColorDefs[MT_COLOR_INDICATOR]);
     mutt_window_move (menu->indexwin, menu->current + menu->offset - 
menu->top, 0);
-    print_enriched_string (cur_color, (unsigned char *) buf, 0);
+    print_enriched_string (cur_color, (unsigned char *) buf, 1);
   }
   menu->redraw &= REDRAW_STATUS;
   NORMAL_COLOR;
@@ -359,17 +371,21 @@ void menu_redraw_current (MUTTMENU *menu)
   menu_make_entry (buf, sizeof (buf), menu, menu->current);
   menu_pad_string (menu, buf, sizeof (buf));
 
-  mutt_attrset_cursor (attr, ColorDefs[MT_COLOR_INDICATOR]);
   if (option (OPTARROWCURSOR))
   {
+    SETCOLOR(MT_COLOR_INDICATOR);
     addstr ("->");
     ATTRSET(attr);
     addch (' ');
     menu_pad_string (menu, buf, sizeof (buf));
-    print_enriched_string (attr, (unsigned char *) buf, 1);
+    print_enriched_string (attr, (unsigned char *) buf, 0);
   }
   else
-    print_enriched_string (attr, (unsigned char *) buf, 0);
+  {
+    mutt_attrset_cursor (attr, ColorDefs[MT_COLOR_INDICATOR]);
+    print_enriched_string (attr, (unsigned char *) buf, 1);
+  }
+
   menu->redraw &= REDRAW_STATUS;
   NORMAL_COLOR;
 }

Reply via email to