color: integrate the hilite attribute into the pair number

Color-pair numbers and attributes can be OR'd together -- do so,
to save an attron() call whenever the hilite is on.
This commit is contained in:
Benno Schulenberg 2016-07-11 22:25:56 +02:00
parent 62eeda3e9f
commit 8507dd4bd0
3 changed files with 3 additions and 20 deletions

View File

@ -62,8 +62,9 @@ void set_colorpairs(void)
if (background == -1 && !using_defaults)
background = COLOR_BLACK;
init_pair(i + 1, foreground, background);
interface_color_pair[i].bright = bright;
interface_color_pair[i].pairnum = COLOR_PAIR(i + 1);
interface_color_pair[i].bright = FALSE;
interface_color_pair[i].pairnum =
COLOR_PAIR(i + 1) | (bright ? A_BOLD : A_NORMAL);
}
else {
interface_color_pair[i].bright = FALSE;

View File

@ -491,8 +491,6 @@ void update_the_statusbar(void)
index = strnlenpt(answer, statusbar_x);
page_start = get_statusbar_page_start(start_col, start_col + index);
if (interface_color_pair[TITLE_BAR].bright)
wattron(bottomwin, A_BOLD);
wattron(bottomwin, interface_color_pair[TITLE_BAR].pairnum);
blank_statusbar();
@ -505,7 +503,6 @@ void update_the_statusbar(void)
waddstr(bottomwin, expanded);
free(expanded);
wattroff(bottomwin, A_BOLD);
wattroff(bottomwin, interface_color_pair[TITLE_BAR].pairnum);
statusbar_pww = statusbar_xplustabs();
@ -855,14 +852,11 @@ int do_yesno_prompt(bool all, const char *msg)
onekey("^C", _("Cancel"), width);
}
if (interface_color_pair[TITLE_BAR].bright)
wattron(bottomwin, A_BOLD);
wattron(bottomwin, interface_color_pair[TITLE_BAR].pairnum);
blank_statusbar();
mvwaddnstr(bottomwin, 0, 0, msg, actual_x(msg, COLS - 1));
wattroff(bottomwin, A_BOLD);
wattroff(bottomwin, interface_color_pair[TITLE_BAR].pairnum);
/* Refresh edit window and statusbar before getting input. */

View File

@ -1868,8 +1868,6 @@ void titlebar(const char *path)
assert(path != NULL || openfile->filename != NULL);
if (interface_color_pair[TITLE_BAR].bright)
wattron(topwin, A_BOLD);
wattron(topwin, interface_color_pair[TITLE_BAR].pairnum);
blank_titlebar();
@ -1957,7 +1955,6 @@ void titlebar(const char *path)
else if (statelen > 0)
mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
wattroff(topwin, A_BOLD);
wattroff(topwin, interface_color_pair[TITLE_BAR].pairnum);
wnoutrefresh(topwin);
@ -2027,14 +2024,11 @@ void statusline(message_type importance, const char *msg, ...)
start_x = (COLS - strlenpt(foo) - 4) / 2;
wmove(bottomwin, 0, start_x);
if (interface_color_pair[STATUS_BAR].bright)
wattron(bottomwin, A_BOLD);
wattron(bottomwin, interface_color_pair[STATUS_BAR].pairnum);
waddstr(bottomwin, "[ ");
waddstr(bottomwin, foo);
free(foo);
waddstr(bottomwin, " ]");
wattroff(bottomwin, A_BOLD);
wattroff(bottomwin, interface_color_pair[STATUS_BAR].pairnum);
/* Push the message to the screen straightaway. */
@ -2132,22 +2126,16 @@ void onekey(const char *keystroke, const char *desc, int length)
{
assert(keystroke != NULL && desc != NULL);
if (interface_color_pair[KEY_COMBO].bright)
wattron(bottomwin, A_BOLD);
wattron(bottomwin, interface_color_pair[KEY_COMBO].pairnum);
waddnstr(bottomwin, keystroke, actual_x(keystroke, length));
wattroff(bottomwin, A_BOLD);
wattroff(bottomwin, interface_color_pair[KEY_COMBO].pairnum);
length -= strlenpt(keystroke) + 1;
if (length > 0) {
waddch(bottomwin, ' ');
if (interface_color_pair[FUNCTION_TAG].bright)
wattron(bottomwin, A_BOLD);
wattron(bottomwin, interface_color_pair[FUNCTION_TAG].pairnum);
waddnstr(bottomwin, desc, actual_x(desc, length));
wattroff(bottomwin, A_BOLD);
wattroff(bottomwin, interface_color_pair[FUNCTION_TAG].pairnum);
}
}