Encapsulate a curses function to reduce dependencies.
curs_lib.o edit.o editmsg.o enriched.o enter.o filter.o flags.o \
git_ver.o handler.o hdrline.o help.o hook.o icommands.o index.o init.o \
keymap.o mailcap.o main.o menu.o mutt_account.o mutt_attach.o \
- mutt_body.o mutt_header.o mutt_history.o mutt_logging.o mutt_mailbox.o \
+ mutt_body.o mutt_curses.o mutt_header.o mutt_history.o mutt_logging.o mutt_mailbox.o \
mutt_parse.o mutt_signal.o mutt_socket.o mutt_thread.o mutt_window.o \
muttlib.o mx.o myvar.o pager.o pattern.o postpone.o progress.o query.o \
recvattach.o recvcmd.o resize.o rfc3676.o score.o send.o sendlib.o \
{
struct Email *e = rd->email;
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ 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;
if ((e->security & (SEC_ENCRYPT | SEC_SIGN)) == (SEC_ENCRYPT | SEC_SIGN))
{
- SET_COLOR(MT_COLOR_COMPOSE_SECURITY_BOTH);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_BOTH);
addstr(_("Sign, Encrypt"));
}
else if (e->security & SEC_ENCRYPT)
{
- SET_COLOR(MT_COLOR_COMPOSE_SECURITY_ENCRYPT);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_ENCRYPT);
addstr(_("Encrypt"));
}
else if (e->security & SEC_SIGN)
{
- SET_COLOR(MT_COLOR_COMPOSE_SECURITY_SIGN);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_SIGN);
addstr(_("Sign"));
}
else
{
/* L10N: This refers to the encryption of the email, e.g. "Security: None" */
- SET_COLOR(MT_COLOR_COMPOSE_SECURITY_NONE);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_NONE);
addstr(_("None"));
}
NORMAL_COLOR;
if (((WithCrypto & APPLICATION_PGP) != 0) &&
(e->security & APPLICATION_PGP) && (e->security & SEC_SIGN))
{
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER);
printw("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO]));
NORMAL_COLOR;
printw("%s", C_PgpSignAs ? C_PgpSignAs : _("<default>"));
if (((WithCrypto & APPLICATION_SMIME) != 0) &&
(e->security & APPLICATION_SMIME) && (e->security & SEC_SIGN))
{
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER);
printw("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO]));
NORMAL_COLOR;
printw("%s", C_SmimeSignAs ? C_SmimeSignAs : _("<default>"));
if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME) &&
(e->security & SEC_ENCRYPT) && C_SmimeEncryptWith)
{
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER);
mutt_window_mvprintw(rd->win, HDR_CRYPTINFO, 40, "%s", _("Encrypt with: "));
NORMAL_COLOR;
printw("%s", NONULL(C_SmimeEncryptWith));
mutt_window_clrtoeol(rd->win);
if (C_Autocrypt)
{
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER);
printw("%*s", HeaderPadding[HDR_AUTOCRYPT], _(Prompts[HDR_AUTOCRYPT]));
NORMAL_COLOR;
if (e->security & SEC_AUTOCRYPT)
{
- SET_COLOR(MT_COLOR_COMPOSE_SECURITY_ENCRYPT);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_ENCRYPT);
addstr(_("Encrypt"));
}
else
{
- SET_COLOR(MT_COLOR_COMPOSE_SECURITY_NONE);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_SECURITY_NONE);
addstr(_("Off"));
}
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER);
mutt_window_mvprintw(rd->win, HDR_AUTOCRYPT, 40, "%s",
/* L10N:
The autocrypt compose menu Recommendation field.
{
char *t = NULL;
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ 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;
buf[0] = '\0';
mutt_addrlist_write(buf, sizeof(buf), al, true);
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER);
mutt_window_mvprintw(rd->win, line, 0, "%*s", HeaderPadding[line], _(Prompts[line]));
NORMAL_COLOR;
mutt_paddstr(W, buf);
}
#endif
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ 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;
draw_envelope_addr(HDR_REPLYTO, &e->env->reply_to, rd);
- SET_COLOR(MT_COLOR_COMPOSE_HEADER);
+ 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;
redraw_mix_line(&e->chain, rd);
#endif
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_window_mvaddstr(rd->win, HDR_ATTACH_TITLE, 0, _("-- Attachments"));
mutt_window_clrtoeol(rd->win);
compose_status_line(buf, sizeof(buf), 0, menu->statuswin->cols, menu,
NONULL(C_ComposeFormat));
mutt_window_move(menu->statuswin, 0, 0);
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_paddstr(menu->statuswin->cols, buf);
NORMAL_COLOR;
menu->redraw &= ~REDRAW_STATUS;
mutt_menu_current_redraw();
}
mutt_window_clearline(MuttMessageWindow, 0);
- SET_COLOR(MT_COLOR_PROMPT);
+ mutt_curses_set_color(MT_COLOR_PROMPT);
addstr(field);
NORMAL_COLOR;
mutt_refresh();
((size_t) prompt_lines * MuttMessageWindow->cols) - answer_string_wid, NULL);
mutt_window_move(MuttMessageWindow, 0, 0);
- SET_COLOR(MT_COLOR_PROMPT);
+ mutt_curses_set_color(MT_COLOR_PROMPT);
addnstr(msg, trunc_msg_len);
addstr(answer_string);
NORMAL_COLOR;
if (OptKeepQuiet || !ErrorBufMessage)
return;
- SET_COLOR(OptMsgErr ? MT_COLOR_ERROR : MT_COLOR_MESSAGE);
+ mutt_curses_set_color(OptMsgErr ? MT_COLOR_ERROR : MT_COLOR_MESSAGE);
mutt_window_mvaddstr(MuttMessageWindow, 0, 0, ErrorBuf);
NORMAL_COLOR;
mutt_window_clrtoeol(MuttMessageWindow);
{
struct KeyEvent ch;
- SET_COLOR(MT_COLOR_PROMPT);
+ mutt_curses_set_color(MT_COLOR_PROMPT);
mutt_window_mvaddstr(MuttMessageWindow, 0, 0, prompt);
addstr(_(" ('?' for list): "));
NORMAL_COLOR;
while ((cur = strchr(prompt, '(')))
{
// write the part between prompt and cur using MT_COLOR_PROMPT
- SET_COLOR(MT_COLOR_PROMPT);
+ mutt_curses_set_color(MT_COLOR_PROMPT);
addnstr(prompt, cur - prompt);
if (isalnum(cur[1]) && (cur[2] == ')'))
{
// we have a single letter within parentheses
- SET_COLOR(MT_COLOR_OPTIONS);
+ mutt_curses_set_color(MT_COLOR_OPTIONS);
addch(cur[1]);
prompt = cur + 3;
}
}
}
- SET_COLOR(MT_COLOR_PROMPT);
+ mutt_curses_set_color(MT_COLOR_PROMPT);
addstr(prompt);
NORMAL_COLOR;
char buf[1024];
menu_status_line(buf, sizeof(buf), menu, NONULL(C_StatusFormat));
mutt_window_move(menu->statuswin, 0, 0);
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_draw_statusline(menu->statuswin->cols, buf, sizeof(buf));
NORMAL_COLOR;
menu->redraw &= ~REDRAW_STATUS;
* may be undefined. */
ATTR_SET(mutt_color_combine(ColorDefs[MT_COLOR_TREE], attr));
#else
- SET_COLOR(MT_COLOR_TREE);
+ mutt_curses_set_color(MT_COLOR_TREE);
#endif
while (*s && (*s < MUTT_TREE_MAX))
if (C_Help)
{
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_window_move(MuttHelpWindow, 0, 0);
mutt_paddstr(MuttHelpWindow->cols, menu->help);
NORMAL_COLOR;
char buf[256];
snprintf(buf, sizeof(buf), "-- NeoMutt: %s", menu->title);
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_window_move(menu->statuswin, 0, 0);
mutt_paddstr(menu->statuswin->cols, buf);
NORMAL_COLOR;
if (i == menu->current)
{
- SET_COLOR(MT_COLOR_INDICATOR);
+ mutt_curses_set_color(MT_COLOR_INDICATOR);
if (C_ArrowCursor)
{
addstr("->");
}
/* now draw it in the new location */
- SET_COLOR(MT_COLOR_INDICATOR);
+ mutt_curses_set_color(MT_COLOR_INDICATOR);
mutt_window_mvaddstr(menu->indexwin, menu->current + menu->offset - menu->top, 0, "->");
}
else
const int cur_color = menu->menu_color(menu->current);
menu_make_entry(buf, sizeof(buf), menu, menu->current);
menu_pad_string(menu, buf, sizeof(buf));
- SET_COLOR(MT_COLOR_INDICATOR);
+ mutt_curses_set_color(MT_COLOR_INDICATOR);
mutt_window_move(menu->indexwin, menu->current + menu->offset - menu->top, 0);
print_enriched_string(menu->current, cur_color, (unsigned char *) buf, false);
}
menu_make_entry(buf, sizeof(buf), menu, menu->current);
menu_pad_string(menu, buf, sizeof(buf));
- SET_COLOR(MT_COLOR_INDICATOR);
+ mutt_curses_set_color(MT_COLOR_INDICATOR);
if (C_ArrowCursor)
{
addstr("->");
--- /dev/null
+/**
+ * @file
+ * Define wrapper functions around Curses/Slang
+ *
+ * @authors
+ * Copyright (C) 1996-2000,2012 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 2004 g10 Code GmbH
+ * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
+ *
+ * @copyright
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "mutt_curses.h"
+#include "color.h"
+
+/**
+ * mutt_curses_set_color - Set the current colour for text
+ * @param color Colour to set, e.g. #MT_COLOR_HEADER
+ *
+ * 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.
+ */
+void mutt_curses_set_color(enum ColorId color)
+{
+#ifdef HAVE_BKGDSET
+ if (ColorDefs[color] != 0)
+ bkgdset(ColorDefs[color] | ' ');
+ else
+ bkgdset(ColorDefs[MT_COLOR_NORMAL] | ' ');
+#else
+ if (ColorDefs[color] != 0)
+ attrset(ColorDefs[color]);
+ else
+ attrset(ColorDefs[MT_COLOR_NORMAL]);
+#endif
+}
#include "config.h"
#include <stdbool.h>
+#include "color.h"
#ifdef USE_SLANG_CURSES
#define CI_is_return(ch) (((ch) == '\r') || ((ch) == '\n'))
#endif
+void mutt_curses_set_color(enum ColorId color);
void mutt_resize_screen(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.
- */
#ifdef HAVE_BKGDSET
-#define SET_COLOR(X) \
- do \
- { \
- if (ColorDefs[X] != 0) \
- bkgdset(ColorDefs[X] | ' '); \
- else \
- bkgdset(ColorDefs[MT_COLOR_NORMAL] | ' '); \
- } while (false)
#define ATTR_SET(X) bkgdset(X | ' ')
#else
-#define SET_COLOR(X) \
- do \
- { \
- if (ColorDefs[X] != 0) \
- attrset(ColorDefs[X]); \
- else \
- attrset(ColorDefs[MT_COLOR_NORMAL]); \
- } while (false)
#define ATTR_SET attrset
#endif
{
if (level == LL_ERROR)
BEEP();
- SET_COLOR((level == LL_ERROR) ? MT_COLOR_ERROR : MT_COLOR_MESSAGE);
+ mutt_curses_set_color((level == LL_ERROR) ? MT_COLOR_ERROR : MT_COLOR_MESSAGE);
mutt_window_mvaddstr(MuttMessageWindow, 0, 0, ErrorBuf);
NORMAL_COLOR;
mutt_window_clrtoeol(MuttMessageWindow);
{
if (!cnt && C_Markers)
{
- SET_COLOR(MT_COLOR_MARKERS);
+ mutt_curses_set_color(MT_COLOR_MARKERS);
addch('+');
last_color = ColorDefs[MT_COLOR_MARKERS];
}
if (C_Help)
{
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_window_move(MuttHelpWindow, 0, 0);
mutt_paddstr(MuttHelpWindow->cols, rd->helpstr);
NORMAL_COLOR;
rd->last_offset = rd->line_info[rd->curline].offset;
} while (rd->force_redraw);
- SET_COLOR(MT_COLOR_TILDE);
+ mutt_curses_set_color(MT_COLOR_TILDE);
while (rd->lines < rd->pager_window->rows)
{
mutt_window_clrtoeol(rd->pager_window);
/* print out the pager status bar */
mutt_window_move(rd->pager_status_window, 0, 0);
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
if (IsEmail(rd->extra) || IsMsgAttach(rd->extra))
{
menu_status_line(buf, sizeof(buf), rd->menu, NONULL(C_StatusFormat));
mutt_window_move(rd->index_status_window, 0, 0);
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_draw_statusline(rd->index_status_window->cols, buf, sizeof(buf));
NORMAL_COLOR;
}
if (l < w)
{
/* The string fits within the colour bar */
- SET_COLOR(MT_COLOR_PROGRESS);
+ mutt_curses_set_color(MT_COLOR_PROGRESS);
addstr(buf2);
w -= l;
while (w-- > 0)
char ch = buf2[off];
buf2[off] = '\0';
- SET_COLOR(MT_COLOR_PROGRESS);
+ mutt_curses_set_color(MT_COLOR_PROGRESS);
addstr(buf2);
buf2[off] = ch;
NORMAL_COLOR;
if (coords[i].r < MIX_MAXROW)
{
if (selected)
- SET_COLOR(MT_COLOR_INDICATOR);
+ mutt_curses_set_color(MT_COLOR_INDICATOR);
else
NORMAL_COLOR;
*/
static void mix_redraw_head(struct MixChain *chain)
{
- SET_COLOR(MT_COLOR_STATUS);
+ mutt_curses_set_color(MT_COLOR_STATUS);
mutt_window_mvprintw(MuttIndexWindow, MIX_VOFFSET - 1, 0,
"-- Remailer chain [Length: %d]", chain ? chain->cl : 0);
mutt_window_clrtoeol(MuttIndexWindow);
if (delim_len > num_cols)
return 0;
- SET_COLOR(MT_COLOR_DIVIDER);
+ mutt_curses_set_color(MT_COLOR_DIVIDER);
int col = C_SidebarOnRight ? 0 : (C_SidebarWidth - delim_len);
if (entryidx == OpnIndex)
{
if ((ColorDefs[MT_COLOR_SB_INDICATOR] != 0))
- SET_COLOR(MT_COLOR_SB_INDICATOR);
+ mutt_curses_set_color(MT_COLOR_SB_INDICATOR);
else
- SET_COLOR(MT_COLOR_INDICATOR);
+ mutt_curses_set_color(MT_COLOR_INDICATOR);
}
else if (entryidx == HilIndex)
- SET_COLOR(MT_COLOR_HIGHLIGHT);
+ mutt_curses_set_color(MT_COLOR_HIGHLIGHT);
else if ((m->msg_unread > 0) || (m->has_new))
- SET_COLOR(MT_COLOR_NEW);
+ mutt_curses_set_color(MT_COLOR_NEW);
else if (m->msg_flagged > 0)
- SET_COLOR(MT_COLOR_FLAGGED);
+ mutt_curses_set_color(MT_COLOR_FLAGGED);
else if ((ColorDefs[MT_COLOR_SB_SPOOLFILE] != 0) &&
(mutt_str_strcmp(mailbox_path(m), C_Spoolfile) == 0))
{
- SET_COLOR(MT_COLOR_SB_SPOOLFILE);
+ mutt_curses_set_color(MT_COLOR_SB_SPOOLFILE);
}
else
{
if (ColorDefs[MT_COLOR_ORDINARY] != 0)
- SET_COLOR(MT_COLOR_ORDINARY);
+ mutt_curses_set_color(MT_COLOR_ORDINARY);
else
NORMAL_COLOR;
}