From: Richard Russon Date: Fri, 27 Sep 2019 15:22:13 +0000 (+0100) Subject: refactor: printw() to mutt_window_printf() X-Git-Tag: 2019-10-25~30^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2c85042da8366bdc5bf11670285c09e2907cff8;p=neomutt refactor: printw() to mutt_window_printf() Encapsulate a curses function to reduce dependencies. --- diff --git a/compose.c b/compose.c index a60d6745d..76109a0db 100644 --- a/compose.c +++ b/compose.c @@ -428,18 +428,18 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) (e->security & APPLICATION_PGP) && (e->security & SEC_SIGN)) { mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); - printw("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO])); + mutt_window_printf("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO])); mutt_curses_set_color(MT_COLOR_NORMAL); - printw("%s", C_PgpSignAs ? C_PgpSignAs : _("")); + mutt_window_printf("%s", C_PgpSignAs ? C_PgpSignAs : _("")); } if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME) && (e->security & SEC_SIGN)) { mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); - printw("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO])); + mutt_window_printf("%*s", HeaderPadding[HDR_CRYPTINFO], _(Prompts[HDR_CRYPTINFO])); mutt_curses_set_color(MT_COLOR_NORMAL); - printw("%s", C_SmimeSignAs ? C_SmimeSignAs : _("")); + mutt_window_printf("%s", C_SmimeSignAs ? C_SmimeSignAs : _("")); } if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME) && @@ -448,7 +448,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: ")); mutt_curses_set_color(MT_COLOR_NORMAL); - printw("%s", NONULL(C_SmimeEncryptWith)); + mutt_window_printf("%s", NONULL(C_SmimeEncryptWith)); } #ifdef USE_AUTOCRYPT @@ -457,7 +457,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) if (C_Autocrypt) { mutt_curses_set_color(MT_COLOR_COMPOSE_HEADER); - printw("%*s", HeaderPadding[HDR_AUTOCRYPT], _(Prompts[HDR_AUTOCRYPT])); + mutt_window_printf("%*s", HeaderPadding[HDR_AUTOCRYPT], _(Prompts[HDR_AUTOCRYPT])); mutt_curses_set_color(MT_COLOR_NORMAL); if (e->security & SEC_AUTOCRYPT) { @@ -479,7 +479,7 @@ static void redraw_crypt_lines(struct ComposeRedrawData *rd) */ _("Recommendation: ")); mutt_curses_set_color(MT_COLOR_NORMAL); - printw("%s", _(AutocryptRecUiFlags[rd->autocrypt_rec])); + mutt_window_printf("%s", _(AutocryptRecUiFlags[rd->autocrypt_rec])); } #endif } diff --git a/edit.c b/edit.c index 5cb870b9b..29f7d44ad 100644 --- a/edit.c +++ b/edit.c @@ -182,7 +182,7 @@ static int be_barf_file(const char *path, char **buf, int buflen) fputs(buf[i], fp); if (fclose(fp) == 0) return 0; - printw("fclose: %s\n", strerror(errno)); + mutt_window_printf("fclose: %s\n", strerror(errno)); return -1; } @@ -257,7 +257,7 @@ static char **be_include_messages(char *msg, char **buf, int *bufmax, buf[(*buflen)++] = mutt_str_strdup("\n"); } else - printw(_("%d: invalid message number.\n"), n); + mutt_window_printf(_("%d: invalid message number.\n"), n); msg = NULL; } return buf; @@ -534,7 +534,7 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c mutt_env_to_local(e_new->env); mutt_edit_headers(NONULL(C_Visual), path, e_new, NULL, 0); if (mutt_env_to_intl(e_new->env, &tag, &err)) - printw(_("Bad IDN in '%s': '%s'"), tag, err); + mutt_window_printf(_("Bad IDN in '%s': '%s'"), tag, err); /* tag is a statically allocated string and should not be freed */ FREE(&err); } @@ -554,7 +554,7 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c done = true; break; default: - printw(_("%s: unknown editor command (~? for help)\n"), tmp); + mutt_window_printf(_("%s: unknown editor command (~? for help)\n"), tmp); break; } } diff --git a/enter.c b/enter.c index 3433ebb05..175080106 100644 --- a/enter.c +++ b/enter.c @@ -76,10 +76,10 @@ static int my_addwch(wchar_t wc) if (IsWPrint(wc) && (n > 0)) return mutt_addwch(wc); if (!(wc & ~0x7f)) - return printw("^%c", ((int) wc + 0x40) & 0x7f); + return mutt_window_printf("^%c", ((int) wc + 0x40) & 0x7f); if (!(wc & ~0xffff)) - return printw("\\u%04x", (int) wc); - return printw("\\u%08x", (int) wc); + return mutt_window_printf("\\u%04x", (int) wc); + return mutt_window_printf("\\u%08x", (int) wc); } /** diff --git a/mutt_window.c b/mutt_window.c index f6f9ca6ce..51c484172 100644 --- a/mutt_window.c +++ b/mutt_window.c @@ -411,3 +411,19 @@ void mutt_window_move_abs(int row, int col) { move(row, col); } + +/** + * mutt_window_printf - Write a formatted string to a Window + * @param fmt Format string + * @param ... Arguments + * @retval num Number of characters written + */ +int mutt_window_printf(const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + int rc = vw_printw(stdscr, fmt, ap); + va_end(ap); + + return rc; +} diff --git a/mutt_window.h b/mutt_window.h index 81d2e94cd..ac3c0e6ee 100644 --- a/mutt_window.h +++ b/mutt_window.h @@ -68,5 +68,6 @@ int mutt_window_move (struct MuttWindow *win, int row, int col); void mutt_window_move_abs (int row, int col); int mutt_window_mvaddstr (struct MuttWindow *win, int row, int col, const char *str); int mutt_window_mvprintw (struct MuttWindow *win, int row, int col, const char *fmt, ...); +int mutt_window_printf (const char *format, ...); #endif /* MUTT_MUTT_WINDOW_H */ diff --git a/pager.c b/pager.c index bd0a680fc..5c63186ed 100644 --- a/pager.c +++ b/pager.c @@ -1487,7 +1487,7 @@ static int format_line(struct Line **line_info, int n, unsigned char *buf, break; col += 4; if (pa) - printw("\\%03o", buf[ch]); + mutt_window_printf("\\%03o", buf[ch]); k = 1; continue; } @@ -1586,7 +1586,7 @@ static int format_line(struct Line **line_info, int n, unsigned char *buf, break; col += 2; if (pa) - printw("^%c", ('@' + wc) & 0x7f); + mutt_window_printf("^%c", ('@' + wc) & 0x7f); } else if (wc < 0x100) { @@ -1594,7 +1594,7 @@ static int format_line(struct Line **line_info, int n, unsigned char *buf, break; col += 4; if (pa) - printw("\\%03o", wc); + mutt_window_printf("\\%03o", wc); } else { diff --git a/sidebar.c b/sidebar.c index ba3521379..b0ead8acb 100644 --- a/sidebar.c +++ b/sidebar.c @@ -949,7 +949,7 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) } char str[256]; make_sidebar_entry(str, sizeof(str), w, sidebar_folder_name, entry); - printw("%s", str); + mutt_window_printf("%s", str); mutt_buffer_pool_release(&short_folder_name); row++; }