From: Michael Elkins Date: Mon, 31 Dec 2012 02:49:20 +0000 (-0800) Subject: make the SETCOLOR() macro use bkgdset() on systems which have it, and attrset() when... X-Git-Tag: neomutt-20160307~200 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91a2c2e88b87d50ef591f157a103112652a99f47;p=neomutt make the SETCOLOR() macro use bkgdset() on systems which have it, and attrset() when we don't. closes #3005 --- diff --git a/color.c b/color.c index db8266d0b..ef97ca94b 100644 --- a/color.c +++ b/color.c @@ -769,13 +769,6 @@ _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 - return (r); } diff --git a/compose.c b/compose.c index edda021da..1b329671b 100644 --- a/compose.c +++ b/compose.c @@ -264,11 +264,9 @@ static void draw_envelope (HEADER *msg, char *fcc) SETCOLOR (MT_COLOR_STATUS); mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments")); - BKGDSET (MT_COLOR_STATUS); clrtoeol (); - BKGDSET (MT_COLOR_NORMAL); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; } static int edit_address_list (int line, ADDRESS **addr) @@ -547,9 +545,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ { mutt_str_replace (&msg->env->subject, buf); move (HDR_SUBJECT, HDR_XOFFSET); - clrtoeol (); if (msg->env->subject) mutt_paddstr (W, msg->env->subject); + else + clrtoeol(); } mutt_message_hook (NULL, msg, M_SEND2HOOK); break; @@ -1269,12 +1268,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */ if (menu->redraw & REDRAW_STATUS) { compose_status_line (buf, sizeof (buf), 0, menu, NONULL(ComposeFormat)); - CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); + move(option (OPTSTATUSONTOP) ? 0 : LINES-2, 0); SETCOLOR (MT_COLOR_STATUS); - BKGDSET (MT_COLOR_STATUS); mutt_paddstr (COLS, buf); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); + NORMAL_COLOR; menu->redraw &= ~REDRAW_STATUS; } } diff --git a/curs_lib.c b/curs_lib.c index 291149062..24af11fed 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -321,7 +321,7 @@ static void curses_message (int error, const char *fmt, va_list ap) SETCOLOR (error ? MT_COLOR_ERROR : MT_COLOR_MESSAGE); mvaddstr (LINES-1, 0, Errorbuf); clrtoeol (); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; mutt_refresh (); } @@ -464,9 +464,9 @@ void mutt_show_error (void) return; SETCOLOR (option (OPTMSGERR) ? MT_COLOR_ERROR : MT_COLOR_MESSAGE); - CLEARLINE (LINES-1); - addstr (Errorbuf); - SETCOLOR (MT_COLOR_NORMAL); + mvaddstr(LINES-1, 0, Errorbuf); + clrtoeol(); + NORMAL_COLOR; } void mutt_endwin (const char *msg) @@ -475,9 +475,8 @@ void mutt_endwin (const char *msg) if (!option (OPTNOCURSES)) { + ATTRSET(A_NORMAL); CLEARLINE (LINES - 1); - - attrset (A_NORMAL); mutt_refresh (); endwin (); } diff --git a/curs_main.c b/curs_main.c index 302082b49..b9e34bd58 100644 --- a/curs_main.c +++ b/curs_main.c @@ -555,12 +555,10 @@ int mutt_index_menu (void) if (menu->redraw & REDRAW_STATUS) { menu_status_line (buf, sizeof (buf), menu, NONULL (Status)); - CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2); + move (option (OPTSTATUSONTOP) ? 0 : LINES-2, 0); SETCOLOR (MT_COLOR_STATUS); - BKGDSET (MT_COLOR_STATUS); mutt_paddstr (COLS, buf); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); + NORMAL_COLOR; menu->redraw &= ~REDRAW_STATUS; } diff --git a/menu.c b/menu.c index e3f0e9244..e03dd3301 100644 --- a/menu.c +++ b/menu.c @@ -159,7 +159,7 @@ static void print_enriched_string (int attr, unsigned char *s, int do_color) } s++, n--; } - if (do_color) attrset(attr); + if (do_color) ATTRSET(attr); } else if ((k = mbrtowc (&wc, (char *)s, n, &mbstate)) > 0) { @@ -195,7 +195,7 @@ static void menu_pad_string (char *s, size_t n) void menu_redraw_full (MUTTMENU *menu) { - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; /* clear() doesn't optimize screen redraws */ move (0, 0); clrtobot (); @@ -205,7 +205,7 @@ void menu_redraw_full (MUTTMENU *menu) SETCOLOR (MT_COLOR_STATUS); move (option (OPTSTATUSONTOP) ? LINES-2 : 0, 0); mutt_paddstr (COLS, menu->help); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; menu->offset = 1; menu->pagelen = LINES - 3; } @@ -228,7 +228,7 @@ void menu_redraw_status (MUTTMENU *menu) SETCOLOR (MT_COLOR_STATUS); move (option (OPTSTATUSONTOP) ? 0 : LINES - 2, 0); mutt_paddstr (COLS, buf); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; menu->redraw &= ~REDRAW_STATUS; } @@ -236,55 +236,46 @@ 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++) { if (i < menu->max) { + attr = menu->color(i); + menu_make_entry (buf, sizeof (buf), menu, i); menu_pad_string (buf, sizeof (buf)); - if (option (OPTARROWCURSOR)) - { - attrset (menu->color (i)); - CLEARLINE (i - menu->top + menu->offset); - - if (i == menu->current) - { - attrset (menu->color (i)); - ADDCOLOR (MT_COLOR_INDICATOR); - addstr ("->"); - attrset (menu->color (i)); - addch (' '); - } - else - { - attrset (menu->color (i)); - addstr (" "); - } + ATTRSET(attr); + move(i - menu->top + menu->offset, 0); + do_color = 1; - print_enriched_string (menu->color(i), (unsigned char *) buf, 1); - SETCOLOR (MT_COLOR_NORMAL); - } - else + if (i == menu->current) { - attrset (menu->color (i)); - - if (i == menu->current) - { - ADDCOLOR (MT_COLOR_INDICATOR); - BKGDSET (MT_COLOR_INDICATOR); - } - - CLEARLINE (i - menu->top + menu->offset); - print_enriched_string (menu->color(i), (unsigned char *) buf, i != menu->current); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); + SETCOLOR(MT_COLOR_INDICATOR); + if (option(OPTARROWCURSOR)) + { + addstr ("->"); + ATTRSET(attr); + addch (' '); + } + else + do_color = 0; } + else if (option(OPTARROWCURSOR)) + addstr(" "); + + print_enriched_string (attr, (unsigned char *) buf, do_color); } else - CLEARLINE (i - menu->top + menu->offset); + { + NORMAL_COLOR; + CLEARLINE(i - menu->top + menu->offset); + } } + NORMAL_COLOR; menu->redraw = 0; } @@ -299,37 +290,28 @@ void menu_redraw_motion (MUTTMENU *menu) } move (menu->oldcurrent + menu->offset - menu->top, 0); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); + ATTRSET(menu->color (menu->oldcurrent)); if (option (OPTARROWCURSOR)) { /* clear the pointer */ - attrset (menu->color (menu->oldcurrent)); addstr (" "); if (menu->redraw & REDRAW_MOTION_RESYNCH) { - clrtoeol (); menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); menu_pad_string (buf, sizeof (buf)); move (menu->oldcurrent + menu->offset - menu->top, 3); print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1); - SETCOLOR (MT_COLOR_NORMAL); } /* now draw it in the new location */ - move (menu->current + menu->offset - menu->top, 0); - attrset (menu->color (menu->current)); - ADDCOLOR (MT_COLOR_INDICATOR); - addstr ("->"); - SETCOLOR (MT_COLOR_NORMAL); + SETCOLOR(MT_COLOR_INDICATOR); + mvaddstr(menu->current + menu->offset - menu->top, 0, "->"); } else { /* erase the current indicator */ - attrset (menu->color (menu->oldcurrent)); - clrtoeol (); menu_make_entry (buf, sizeof (buf), menu, menu->oldcurrent); menu_pad_string (buf, sizeof (buf)); print_enriched_string (menu->color(menu->oldcurrent), (unsigned char *) buf, 1); @@ -337,50 +319,36 @@ void menu_redraw_motion (MUTTMENU *menu) /* now draw the new one to reflect the change */ menu_make_entry (buf, sizeof (buf), menu, menu->current); menu_pad_string (buf, sizeof (buf)); - attrset (menu->color (menu->current)); - ADDCOLOR (MT_COLOR_INDICATOR); - BKGDSET (MT_COLOR_INDICATOR); - CLEARLINE (menu->current - menu->top + menu->offset); + SETCOLOR(MT_COLOR_INDICATOR); + move(menu->current - menu->top + menu->offset, 0); print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); } menu->redraw &= REDRAW_STATUS; + NORMAL_COLOR; } void menu_redraw_current (MUTTMENU *menu) { char buf[LONG_STRING]; + int attr = menu->color (menu->current); move (menu->current + menu->offset - menu->top, 0); menu_make_entry (buf, sizeof (buf), menu, menu->current); menu_pad_string (buf, sizeof (buf)); + SETCOLOR(MT_COLOR_INDICATOR); if (option (OPTARROWCURSOR)) { - int attr = menu->color (menu->current); - attrset (attr); - clrtoeol (); - attrset (menu->color (menu->current)); - ADDCOLOR (MT_COLOR_INDICATOR); addstr ("->"); - attrset (attr); + ATTRSET(attr); addch (' '); menu_pad_string (buf, sizeof (buf)); - print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 1); - SETCOLOR (MT_COLOR_NORMAL); + print_enriched_string (attr, (unsigned char *) buf, 1); } else - { - attrset (menu->color (menu->current)); - ADDCOLOR (MT_COLOR_INDICATOR); - BKGDSET (MT_COLOR_INDICATOR); - clrtoeol (); - print_enriched_string (menu->color(menu->current), (unsigned char *) buf, 0); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); - } + print_enriched_string (attr, (unsigned char *) buf, 0); menu->redraw &= REDRAW_STATUS; + NORMAL_COLOR; } static void menu_redraw_prompt (MUTTMENU *menu) @@ -396,7 +364,6 @@ static void menu_redraw_prompt (MUTTMENU *menu) if (*Errorbuf) mutt_clear_error (); - SETCOLOR (MT_COLOR_NORMAL); mvaddstr (LINES - 1, 0, menu->prompt); clrtoeol (); } diff --git a/mutt_curses.h b/mutt_curses.h index 854e3d5cf..f8d6f88ae 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -72,12 +72,6 @@ #define curs_set(x) #endif -#if !defined(USE_SLANG_CURSES) && defined(HAVE_BKGDSET) -#define BKGDSET(x) bkgdset (ColorDefs[x] | ' ') -#else -#define BKGDSET(x) -#endif - #if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET)) void mutt_curs_set (int); #else @@ -183,8 +177,20 @@ extern COLOR_LINE *ColorIndexList; void ci_init_color (void); void ci_start_color (void); +/* If the system has bkgdset() use it rather than attrset() so that the clr*() + * functions will properly set the background attributes all the way to the + * right column. + */ +#if defined(HAVE_BKGDSET) +#define SETCOLOR(X) bkgdset(ColorDefs[X] | ' ') +#define ATTRSET(X) bkgdset(X | ' ') +#else #define SETCOLOR(X) attrset(ColorDefs[X]) -#define ADDCOLOR(X) attron(ColorDefs[X]) +#define ATTRSET attrset +#endif + +/* reset the color to the normal terminal color as defined by 'color normal ...' */ +#define NORMAL_COLOR SETCOLOR(MT_COLOR_NORMAL) #define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); x = REDRAW_FULL; } diff --git a/pager.c b/pager.c index ece6e8b3e..9635cc4ae 100644 --- a/pager.c +++ b/pager.c @@ -299,7 +299,7 @@ resolve_color (struct line_t *lineInfo, int n, int cnt, int flags, int special, if (color != last_color) { - attrset (color); + ATTRSET (color); last_color = color; } } @@ -1460,7 +1460,7 @@ display_line (FILE *f, LOFF_T *last_pos, struct line_t **lineInfo, int n, #ifndef USE_SLANG_CURSES if (col == 0) { - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; addch (' '); } #endif @@ -1482,10 +1482,7 @@ display_line (FILE *f, LOFF_T *last_pos, struct line_t **lineInfo, int n, else def_color = ColorDefs[ (*lineInfo)[m].type ]; - attrset (def_color); -#ifdef HAVE_BKGDSET - bkgdset (def_color | ' '); -#endif + ATTRSET(def_color); } /* ncurses always wraps lines when you get to the right side of the @@ -1503,10 +1500,7 @@ display_line (FILE *f, LOFF_T *last_pos, struct line_t **lineInfo, int n, * filled to the right margin. */ if (flags & M_SHOWCOLOR) - { - SETCOLOR(MT_COLOR_NORMAL); - BKGDSET(MT_COLOR_NORMAL); - } + NORMAL_COLOR; /* build a return code */ if (!(flags & M_SHOW)) @@ -1643,7 +1637,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) if (redraw & REDRAW_FULL) { - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; /* clear() doesn't optimize screen redraws */ move (0, 0); clrtobot (); @@ -1681,7 +1675,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) SETCOLOR (MT_COLOR_STATUS); move (helpoffset, 0); mutt_paddstr (COLS, helpstr); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; } #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM) @@ -1714,7 +1708,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) index->current = extra->hdr->virtual; } - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; index->offset = indexoffset + (option (OPTSTATUSONTOP) ? 1 : 0); index->pagelen = indexlen - 1; @@ -1770,7 +1764,6 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) } while (force_redraw); SETCOLOR (MT_COLOR_TILDE); - BKGDSET (MT_COLOR_TILDE); while (lines < bodylen) { clrtoeol (); @@ -1779,6 +1772,8 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) addch ('\n'); lines++; } + NORMAL_COLOR; + /* We are going to update the pager status bar, so it isn't * necessary to reset to normal color now. */ @@ -1800,8 +1795,6 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) /* print out the pager status bar */ SETCOLOR (MT_COLOR_STATUS); - BKGDSET (MT_COLOR_STATUS); - CLEARLINE (statusoffset); if (IsHeader (extra) || IsMsgAttach (extra)) { @@ -1817,8 +1810,7 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) snprintf (bn, sizeof (bn), "%s (%s)", banner, pager_progress_str); mutt_paddstr (COLS, bn); } - BKGDSET (MT_COLOR_NORMAL); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; } if ((redraw & REDRAW_INDEX) && index) @@ -1832,10 +1824,8 @@ mutt_pager (const char *banner, const char *fname, int flags, pager_t *extra) move (indexoffset + (option (OPTSTATUSONTOP) ? 0 : (indexlen - 1)), 0); SETCOLOR (MT_COLOR_STATUS); - BKGDSET (MT_COLOR_STATUS); mutt_paddstr (COLS, buffer); - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); + NORMAL_COLOR; } redraw = 0; diff --git a/remailer.c b/remailer.c index 06eae3e06..fe9c7f243 100644 --- a/remailer.c +++ b/remailer.c @@ -285,10 +285,10 @@ static void mix_redraw_ce (REMAILER **type2_list, if (selected) SETCOLOR (MT_COLOR_INDICATOR); else - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; mvaddstr (coords[i].r, coords[i].c, type2_list[chain->ch[i]]->shortname); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; if (i + 1 < chain->cl) addstr (", "); @@ -302,9 +302,6 @@ static void mix_redraw_chain (REMAILER **type2_list, { int i; - SETCOLOR (MT_COLOR_NORMAL); - BKGDSET (MT_COLOR_NORMAL); - for (i = MIX_VOFFSET; i < MIX_MAXROW; i++) { move (i, 0); @@ -319,12 +316,8 @@ static void mix_redraw_head (MIXCHAIN *chain) { SETCOLOR (MT_COLOR_STATUS); mvprintw (MIX_VOFFSET - 1, 0, "-- Remailer chain [Length: %d]", chain ? chain->cl : 0); - - BKGDSET (MT_COLOR_STATUS); clrtoeol (); - - BKGDSET (MT_COLOR_NORMAL); - SETCOLOR (MT_COLOR_NORMAL); + NORMAL_COLOR; } static const char *mix_format_caps (REMAILER *r)