From: Richard Russon Date: Fri, 27 Sep 2019 12:51:34 +0000 (+0100) Subject: refactor: NORMAL_COLOR() to mutt_curses_set_color() X-Git-Tag: 2019-10-25~30^2~12 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc799d229596ab93c6afc788d62890aa08015d0c;p=neomutt refactor: NORMAL_COLOR() to mutt_curses_set_color() Encapsulate a curses function to reduce dependencies. --- diff --git a/compose.c b/compose.c index dd46652e3..5323e12df 100644 --- a/compose.c +++ b/compose.c @@ -373,7 +373,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw(rd->win, HDR_CRYPT, 0, "%*s", HeaderPadding[HDR_CRYPT], _(Prompts[HDR_CRYPT])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if ((WithCrypto & (APPLICATION_PGP | APPLICATION_SMIME)) == 0) { @@ -402,7 +402,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_NONE); addstr(_("None")); } - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if ((e->security & (SEC_ENCRYPT | SEC_SIGN))) { @@ -429,7 +429,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) { mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); printw("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); printw("%s", C_PgpSignAs ? C_PgpSignAs : _("")); } @@ -438,7 +438,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) { mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); printw("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); printw("%s", C_SmimeSignAs ? C_SmimeSignAs : _("")); } @@ -447,7 +447,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) { mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw(rd->win, HDR_CRYPTINFO, 40, "%s", _("Encrypt with: ")); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); printw("%s", NONULL(C_SmimeEncryptWith)); } @@ -458,7 +458,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) { mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); printw("%*s", HeaderPadding[HDR_AUTOCRYPT], _(Prompts[HDR_AUTOCRYPT])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if (e->security & SEC_AUTOCRYPT) { mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_ENCRYPT); @@ -478,7 +478,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) (Off, No, Discouraged, Available, Yes) */ _("Recommendation: ")); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); printw("%s", _(AutocryptRecUiFlags[rd->autocrypt_rec])); } #endif @@ -537,7 +537,7 @@ static void redraw_mix_line(struct ListHead *chain, struct ComposeRedrawData *rd mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw(rd->win, HDR_MIX, 0, "%*s", HeaderPadding[HDR_MIX], _(Prompts[HDR_MIX])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if (STAILQ_EMPTY(chain)) { @@ -619,7 +619,7 @@ static void draw_envelope_addr(int line, struct AddressList *al, struct ComposeR mutt_addrlist_write(buf, sizeof(buf), al, true); mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw(rd->win, line, 0, "%*s", HeaderPadding[line], _(Prompts[line])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_paddstr(W, buf); } @@ -662,7 +662,7 @@ static void draw_envelope(struct ComposeRedrawData *rd) mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw(rd->win, HDR_SUBJECT, 0, "%*s", HeaderPadding[HDR_SUBJECT], _(Prompts[HDR_SUBJECT])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_paddstr(W, NONULL(e->env->subject)); draw_envelope_addr(HDR_REPLYTO, &e->env->reply_to, rd); @@ -670,7 +670,7 @@ static void draw_envelope(struct ComposeRedrawData *rd) mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); mutt_window_mvprintw(rd->win, HDR_FCC, 0, "%*s", HeaderPadding[HDR_FCC], _(Prompts[HDR_FCC])); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_paddstr(W, fcc); if (WithCrypto) @@ -684,7 +684,7 @@ static void draw_envelope(struct ComposeRedrawData *rd) mutt_window_mvaddstr(rd->win, HDR_ATTACH_TITLE, 0, _("-- Attachments")); mutt_window_clrtoeol(rd->win); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } /** @@ -868,7 +868,7 @@ static void compose_custom_redraw(struct Menu *menu) mutt_window_move(menu->statuswin, 0, 0); mutt_curses_set_color(MT_COLOR_STATUS); mutt_paddstr(menu->statuswin->cols, buf); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; } diff --git a/curs_lib.c b/curs_lib.c index 29e6a9742..47026e775 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -264,7 +264,7 @@ int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionF mutt_window_clearline(MuttMessageWindow, 0); mutt_curses_set_color(MT_COLOR_PROMPT); addstr(field); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_refresh(); mutt_window_getxy(MuttMessageWindow, &x, NULL); ret = mutt_enter_string_full(buf, buflen, x, complete, multiple, files, numfiles, es); @@ -395,7 +395,7 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def) mutt_curses_set_color(MT_COLOR_PROMPT); addnstr(msg, trunc_msg_len); addstr(answer_string); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_window_clrtoeol(MuttMessageWindow); } @@ -490,7 +490,7 @@ void mutt_show_error(void) mutt_curses_set_color(OptMsgErr ? MT_COLOR_ERROR : MT_COLOR_MESSAGE); mutt_window_mvaddstr(MuttMessageWindow, 0, 0, ErrorBuf); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_window_clrtoeol(MuttMessageWindow); } @@ -659,7 +659,7 @@ int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname, mutt_curses_set_color(MT_COLOR_PROMPT); mutt_window_mvaddstr(MuttMessageWindow, 0, 0, prompt); addstr(_(" ('?' for list): ")); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if (!mutt_buffer_is_empty(fname)) addstr(mutt_b2s(fname)); mutt_window_clrtoeol(MuttMessageWindow); @@ -911,7 +911,7 @@ int mutt_multi_choice(const char *prompt, const char *letters) mutt_curses_set_color(MT_COLOR_PROMPT); addstr(prompt); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); addch(' '); mutt_window_clrtoeol(MuttMessageWindow); diff --git a/index.c b/index.c index 6d32ca29d..d989d2d86 100644 --- a/index.c +++ b/index.c @@ -1011,7 +1011,7 @@ static void index_custom_redraw(struct Menu *menu) mutt_window_move(menu->statuswin, 0, 0); mutt_curses_set_color(MT_COLOR_STATUS); mutt_draw_statusline(menu->statuswin->cols, buf, sizeof(buf)); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; if (C_TsEnabled && TsSupported) { diff --git a/main.c b/main.c index 8c738917e..1b7e8f56c 100644 --- a/main.c +++ b/main.c @@ -790,7 +790,7 @@ int main(int argc, char *argv[], char *envp[]) if (!OptNoCurses) { - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); clear(); MuttLogger = log_disp_curses; log_queue_flush(log_disp_curses); diff --git a/menu.c b/menu.c index a5caa6753..e210fe7f3 100644 --- a/menu.c +++ b/menu.c @@ -360,7 +360,7 @@ static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen) */ void menu_redraw_full(struct Menu *menu) { - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); /* clear() doesn't optimize screen redraws */ move(0, 0); clrtobot(); @@ -370,7 +370,7 @@ void menu_redraw_full(struct Menu *menu) mutt_curses_set_color(MT_COLOR_STATUS); mutt_window_move(MuttHelpWindow, 0, 0); mutt_paddstr(MuttHelpWindow->cols, menu->help); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } menu->offset = 0; menu->pagelen = menu->indexwin->rows; @@ -395,7 +395,7 @@ void menu_redraw_status(struct Menu *menu) mutt_curses_set_color(MT_COLOR_STATUS); mutt_window_move(menu->statuswin, 0, 0); mutt_paddstr(menu->statuswin->cols, buf); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); menu->redraw &= ~REDRAW_STATUS; } @@ -453,11 +453,11 @@ void menu_redraw_index(struct Menu *menu) } else { - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_window_clearline(menu->indexwin, i - menu->top + menu->offset); } } - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); menu->redraw = 0; } @@ -516,7 +516,7 @@ void menu_redraw_motion(struct Menu *menu) print_enriched_string(menu->current, cur_color, (unsigned char *) buf, false); } menu->redraw &= REDRAW_STATUS; - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } /** @@ -544,7 +544,7 @@ void menu_redraw_current(struct Menu *menu) else print_enriched_string(menu->current, attr, (unsigned char *) buf, false); menu->redraw &= REDRAW_STATUS; - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } /** diff --git a/mutt_curses.h b/mutt_curses.h index 7ba196586..6c76e01f9 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -111,11 +111,4 @@ void mutt_resize_screen(void); #define ATTR_SET attrset #endif -/* reset the color to the normal terminal color as defined by 'color normal ...' */ -#ifdef HAVE_BKGDSET -#define NORMAL_COLOR bkgdset(ColorDefs[MT_COLOR_NORMAL] | ' ') -#else -#define NORMAL_COLOR attrset(ColorDefs[MT_COLOR_NORMAL]) -#endif - #endif /* MUTT_MUTT_CURSES_H */ diff --git a/mutt_logging.c b/mutt_logging.c index ba9b88be8..b75396b25 100644 --- a/mutt_logging.c +++ b/mutt_logging.c @@ -174,7 +174,7 @@ int log_disp_curses(time_t stamp, const char *file, int line, BEEP(); mutt_curses_set_color((level == LL_ERROR) ? MT_COLOR_ERROR : MT_COLOR_MESSAGE); mutt_window_mvaddstr(MuttMessageWindow, 0, 0, ErrorBuf); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_window_clrtoeol(MuttMessageWindow); mutt_refresh(); } diff --git a/pager.c b/pager.c index c9c746e4b..84743ce7d 100644 --- a/pager.c +++ b/pager.c @@ -1855,7 +1855,7 @@ static int display_line(FILE *fp, LOFF_T *last_pos, struct Line **line_info, #ifndef USE_SLANG_CURSES if (col == 0) { - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); addch(' '); } #endif @@ -1885,7 +1885,7 @@ static int display_line(FILE *fp, LOFF_T *last_pos, struct Line **line_info, * clrtoeol, otherwise the color for this line will not be * filled to the right margin. */ if (flags & MUTT_SHOWCOLOR) - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); /* build a return code */ if (!(flags & MUTT_SHOW)) @@ -1941,7 +1941,7 @@ static void pager_custom_redraw(struct Menu *pager_menu) if (pager_menu->redraw & REDRAW_FULL) { - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); /* clear() doesn't optimize screen redraws */ move(0, 0); clrtobot(); @@ -1994,7 +1994,7 @@ static void pager_custom_redraw(struct Menu *pager_menu) mutt_curses_set_color(MT_COLOR_STATUS); mutt_window_move(MuttHelpWindow, 0, 0); mutt_paddstr(MuttHelpWindow->cols, rd->helpstr); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } if (Resize) @@ -2037,7 +2037,7 @@ static void pager_custom_redraw(struct Menu *pager_menu) rd->menu->statuswin = rd->index_status_window; } - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); rd->menu->pagelen = rd->index_window->rows; /* some fudge to work out whereabouts the indicator should go */ @@ -2143,7 +2143,7 @@ static void pager_custom_redraw(struct Menu *pager_menu) rd->lines++; mutt_window_move(rd->pager_window, rd->lines, 0); } - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); /* We are going to update the pager status bar, so it isn't * necessary to reset to normal color now. */ @@ -2194,7 +2194,7 @@ static void pager_custom_redraw(struct Menu *pager_menu) snprintf(bn, sizeof(bn), "%s (%s)", rd->banner, pager_progress_str); mutt_draw_statusline(rd->pager_status_window->cols, bn, sizeof(bn)); } - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if (C_TsEnabled && TsSupported && rd->menu) { menu_status_line(buf, sizeof(buf), rd->menu, NONULL(C_TsStatusFormat)); @@ -2217,7 +2217,7 @@ static void pager_custom_redraw(struct Menu *pager_menu) mutt_window_move(rd->index_status_window, 0, 0); mutt_curses_set_color(MT_COLOR_STATUS); mutt_draw_statusline(rd->index_status_window->cols, buf, sizeof(buf)); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } pager_menu->redraw = REDRAW_NO_FLAGS; diff --git a/progress.c b/progress.c index d86fa8520..281a08704 100644 --- a/progress.c +++ b/progress.c @@ -88,7 +88,7 @@ static void message_bar(int percent, const char *fmt, ...) { addch(' '); } - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } else { @@ -100,7 +100,7 @@ static void message_bar(int percent, const char *fmt, ...) mutt_curses_set_color(MT_COLOR_PROGRESS); addstr(buf2); buf2[off] = ch; - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); addstr(&buf2[off]); } } diff --git a/remailer.c b/remailer.c index 0cb794d6b..8215cdb53 100644 --- a/remailer.c +++ b/remailer.c @@ -333,11 +333,11 @@ static void mix_redraw_ce(struct Remailer **type2_list, struct Coord *coords, if (selected) mutt_curses_set_color(MT_COLOR_INDICATOR); else - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); mutt_window_mvaddstr(MuttIndexWindow, coords[i].r, coords[i].c, type2_list[chain->ch[i]]->shortname); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if (i + 1 < chain->cl) addstr(", "); @@ -374,7 +374,7 @@ static void mix_redraw_head(struct MixChain *chain) mutt_window_mvprintw(MuttIndexWindow, MIX_VOFFSET - 1, 0, "-- Remailer chain [Length: %d]", chain ? chain->cl : 0); mutt_window_clrtoeol(MuttIndexWindow); - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } /** diff --git a/sidebar.c b/sidebar.c index 8b2ae9e9c..7a12ff697 100644 --- a/sidebar.c +++ b/sidebar.c @@ -784,7 +784,7 @@ static int draw_divider(int num_rows, int num_cols) static void fill_empty_space(int first_row, int num_rows, int div_width, int num_cols) { /* Fill the remaining rows with blank space */ - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); if (!C_SidebarOnRight) div_width = 0; @@ -856,7 +856,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) if (ColorDefs[MT_COLOR_ORDINARY] != 0) mutt_curses_set_color(MT_COLOR_ORDINARY); else - NORMAL_COLOR; + mutt_curses_set_color(MT_COLOR_NORMAL); } int col = 0;