summaryrefslogtreecommitdiffstats
path: root/menu.c
diff options
context:
space:
mode:
authorMaxim Tarasov <mu@magi.net.ru>2020-07-22 18:22:03 -0700
committerKevin McCarthy <kevin@8t8.us>2020-07-22 18:22:03 -0700
commit12ff55e276a52aaced76a5d9f08d7613416f0dcc (patch)
tree4ad4ddbc57dd3e18b881068da136f161354dff97 /menu.c
parentaa8e6d4c837ee5564905455305e7507f727a2079 (diff)
Add color overlay to print_enriched_string().
It is called by main menu drawing routines and contains its own conditional coloring of a tree component. As is, everything in there gets overwritten by the indicator. Furthermore, do_color parameter specifically disables any coloring in order for indicator highlight to overwrite everything else. We need to merge three colors here: 1) index color; 2) tree color, that is drawn within menu using its own color; 3) indicator color, that, if active, is drawn over both of them. Combining these colors is implemented in that order. After some testing, I think it doesn't make sense to merge colors when $arrow_cursor is on. This part is reverted to the original behavior. Make print_enriched_string() coloring behavior self-contained, instead of assuming the proper base_color is already set. This makes the callers simpler and allows them to only handle $arrow_cursor logic.
Diffstat (limited to 'menu.c')
-rw-r--r--menu.c69
1 files changed, 46 insertions, 23 deletions
diff --git a/menu.c b/menu.c
index 2da07c25..44c2beb9 100644
--- a/menu.c
+++ b/menu.c
@@ -35,20 +35,41 @@ 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;
+
+ if (option (OPTCURSOROVERLAY))
+ {
+ 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]);
+ }
+ }
+ else
+ {
+ tree_color = ColorDefs[MT_COLOR_TREE];
+ if (use_indicator)
+ {
+ tree_color = ColorDefs[MT_COLOR_INDICATOR];
+ base_color = ColorDefs[MT_COLOR_INDICATOR];
+ }
+ }
+
+ ATTRSET (base_color);
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 +186,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 +272,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++)
@@ -262,27 +282,30 @@ void menu_redraw_index (MUTTMENU *menu)
menu_make_entry (buf, sizeof (buf), menu, i);
menu_pad_string (menu, buf, sizeof (buf));
-
- 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;
+ print_enriched_string (attr, (unsigned char *) buf, 1);
+ }
+ else
+ {
+ if (option(OPTARROWCURSOR))
+ {
+ ATTRSET(attr);
+ addstr(" ");
+ }
+ print_enriched_string (attr, (unsigned char *) buf, 0);
}
- else if (option(OPTARROWCURSOR))
- addstr(" ");
-
- print_enriched_string (attr, (unsigned char *) buf, do_color);
}
else
{
@@ -311,13 +334,13 @@ void menu_redraw_motion (MUTTMENU *menu)
* position the cursor for drawing. */
old_color = menu->color (menu->oldcurrent);
mutt_window_move (menu->indexwin, menu->oldcurrent + menu->offset - menu->top, 0);
- ATTRSET(old_color);
cur_color = menu->color (menu->current);
if (option (OPTARROWCURSOR))
{
/* clear the pointer */
+ ATTRSET(old_color);
addstr (" ");
if (menu->redraw & REDRAW_MOTION_RESYNCH)
@@ -325,11 +348,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 +360,13 @@ 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 +381,18 @@ 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);
+ print_enriched_string (attr, (unsigned char *) buf, 1);
+
menu->redraw &= REDRAW_STATUS;
NORMAL_COLOR;
}