Commit 66eeb0a2 authored by Michael Elkins's avatar Michael Elkins

make the SETCOLOR() macro use bkgdset() on systems which have it, and attrset() when we don't.

closes #3005
parent 1d51d39e
......@@ -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);
}
......
......@@ -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;
}
}
......
......@@ -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 ();
}
......
......@@ -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;
}
......
......@@ -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 ();
}
......
......@@ -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; }
......
......@@ -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;
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment