From: Richard Russon Date: Fri, 27 Sep 2019 13:30:53 +0000 (+0100) Subject: refactor: beep() to mutt_beep() X-Git-Tag: 2019-10-25~30^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ecdf8ba851145534fd5633c4dc405131904f6438;p=neomutt refactor: beep() to mutt_beep() Encapsulate a curses function to reduce dependencies. --- diff --git a/alias.c b/alias.c index 56f39ed5c..647dfb31a 100644 --- a/alias.c +++ b/alias.c @@ -46,7 +46,6 @@ #include "curs_lib.h" #include "globals.h" #include "hdrline.h" -#include "mutt_curses.h" #include "muttlib.h" #include "sendlib.h" @@ -448,7 +447,7 @@ retry_name: mutt_addrlist_parse(&alias->addr, buf); if (TAILQ_EMPTY(&alias->addr)) - BEEP(); + mutt_beep(false); if (mutt_addrlist_to_intl(&alias->addr, &err)) { mutt_error(_("Bad IDN: '%s'"), err); diff --git a/curs_lib.c b/curs_lib.c index f9db313d0..19c240a9f 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -89,6 +89,16 @@ static struct KeyEvent *UngetKeyEvents; int MuttGetchTimeout = -1; +/** + * mutt_beep - Irritate the user + * @param force If true, ignore the "$beep" config variable + */ +void mutt_beep(bool force) +{ + if (force || C_Beep) + beep(); +} + /** * mutt_refresh - Force a refresh of the screen */ @@ -427,7 +437,7 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def) } else { - BEEP(); + mutt_beep(false); } } @@ -920,7 +930,7 @@ int mutt_multi_choice(const char *prompt, const char *letters) break; } } - BEEP(); + mutt_beep(false); } if (MuttMessageWindow->rows != 1) { diff --git a/curs_lib.h b/curs_lib.h index 4bfaabd62..27624073c 100644 --- a/curs_lib.h +++ b/curs_lib.h @@ -51,6 +51,7 @@ enum FormatJustify int mutt_addwch(wchar_t wc); int mutt_any_key_to_continue(const char *s); +void mutt_beep(bool force); int mutt_do_pager(const char *banner, const char *tempfile, PagerFlags do_color, struct Pager *info); void mutt_edit_file(const char *editor, const char *file); void mutt_endwin(void); diff --git a/enter.c b/enter.c index 45ad2929c..3433ebb05 100644 --- a/enter.c +++ b/enter.c @@ -308,7 +308,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, if (state->lastchar == 0) goto bye; // Pressing backspace with text in the command prompt should just beep - BEEP(); + mutt_beep(false); } else { @@ -343,7 +343,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, case OP_EDITOR_BACKWARD_CHAR: if (state->curpos == 0) - BEEP(); + mutt_beep(false); else { while (state->curpos && COMB_CHAR(state->wbuf[state->curpos - 1])) @@ -355,7 +355,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, case OP_EDITOR_FORWARD_CHAR: if (state->curpos == state->lastchar) - BEEP(); + mutt_beep(false); else { state->curpos++; @@ -369,7 +369,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, case OP_EDITOR_BACKWARD_WORD: if (state->curpos == 0) - BEEP(); + mutt_beep(false); else { while (state->curpos && iswspace(state->wbuf[state->curpos - 1])) @@ -381,7 +381,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, case OP_EDITOR_FORWARD_WORD: if (state->curpos == state->lastchar) - BEEP(); + mutt_beep(false); else { while ((state->curpos < state->lastchar) && @@ -402,7 +402,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, case OP_EDITOR_DOWNCASE_WORD: if (state->curpos == state->lastchar) { - BEEP(); + mutt_beep(false); break; } while (state->curpos && !iswspace(state->wbuf[state->curpos])) @@ -426,7 +426,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, case OP_EDITOR_DELETE_CHAR: if (state->curpos == state->lastchar) - BEEP(); + mutt_beep(false); else { size_t i = state->curpos; @@ -541,7 +541,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, mutt_mem_realloc(&tempbuf, templen * sizeof(wchar_t)); } else - BEEP(); + mutt_beep(false); replace_part(state, i, buf); } @@ -634,7 +634,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, state->tabs = 0; } else if (mutt_command_complete(buf, buflen, i, state->tabs) == 0) - BEEP(); + mutt_beep(false); replace_part(state, 0, buf); } else if (flags & (MUTT_FILE | MUTT_EFILE)) @@ -671,7 +671,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, memcpy(tempbuf, state->wbuf, templen * sizeof(wchar_t)); } else - BEEP(); /* let the user know that nothing matched */ + mutt_beep(false); /* let the user know that nothing matched */ replace_part(state, 0, buf); } #ifdef USE_NOTMUCH @@ -680,7 +680,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos); size_t len = strlen(buf); if (!mutt_nm_query_complete(buf, buflen, len, state->tabs)) - BEEP(); + mutt_beep(false); replace_part(state, 0, buf); } @@ -688,7 +688,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, { mutt_mb_wcstombs(buf, buflen, state->wbuf, state->curpos); if (!mutt_nm_tag_complete(buf, buflen, state->tabs)) - BEEP(); + mutt_beep(false); replace_part(state, 0, buf); } @@ -715,7 +715,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, case OP_EDITOR_TRANSPOSE_CHARS: if (state->lastchar < 2) - BEEP(); + mutt_beep(false); else { wchar_t t; @@ -732,7 +732,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, break; default: - BEEP(); + mutt_beep(false); } } else @@ -804,7 +804,7 @@ int mutt_enter_string_full(char *buf, size_t buflen, int col, else { mutt_flushinp(); - BEEP(); + mutt_beep(false); } } } diff --git a/flags.c b/flags.c index 8c7e764b2..1d2e8505b 100644 --- a/flags.c +++ b/flags.c @@ -38,7 +38,7 @@ #include "curs_lib.h" #include "globals.h" #include "index.h" -#include "mutt_curses.h" +#include "keymap.h" #include "mutt_menu.h" #include "mutt_window.h" #include "protos.h" @@ -490,7 +490,7 @@ int mutt_change_flag(struct Mailbox *m, struct EmailList *el, bool bf) break; default: - BEEP(); + mutt_beep(false); return -1; } diff --git a/index.c b/index.c index 9f1fdfee6..3143c9a9c 100644 --- a/index.c +++ b/index.c @@ -1144,7 +1144,7 @@ int mutt_index_menu(void) { mutt_message(_("New mail in this mailbox")); if (C_BeepNew) - beep(); + mutt_beep(true); if (C_NewMailCommand) { char cmd[1024]; @@ -1187,7 +1187,7 @@ int mutt_index_menu(void) { menu->redraw |= REDRAW_STATUS; if (C_BeepNew) - beep(); + mutt_beep(true); if (C_NewMailCommand) { char cmd[1024]; diff --git a/mutt_curses.h b/mutt_curses.h index 5b200baa5..89b1bd26e 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -77,13 +77,6 @@ #endif /* USE_SLANG_CURSES */ -#define BEEP() \ - do \ - { \ - if (C_Beep) \ - beep(); \ - } while (false) - #define ctrl(ch) ((ch) - '@') #ifdef KEY_ENTER diff --git a/mutt_logging.c b/mutt_logging.c index b75396b25..84a053327 100644 --- a/mutt_logging.c +++ b/mutt_logging.c @@ -171,7 +171,7 @@ int log_disp_curses(time_t stamp, const char *file, int line, if (!OptKeepQuiet) { if (level == LL_ERROR) - BEEP(); + mutt_beep(false); mutt_curses_set_color((level == LL_ERROR) ? MT_COLOR_ERROR : MT_COLOR_MESSAGE); mutt_window_mvaddstr(MuttMessageWindow, 0, 0, ErrorBuf); mutt_curses_set_color(MT_COLOR_NORMAL); diff --git a/pager.c b/pager.c index 5102aade2..f46c574e3 100644 --- a/pager.c +++ b/pager.c @@ -2445,7 +2445,7 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P if (mutt_mailbox_notify(Context ? Context->mailbox : NULL) || do_new_mail) { if (C_BeepNew) - beep(); + mutt_beep(true); if (C_NewMailCommand) { char cmd[1024];