From 4cd70a5f72c3548d6bccceabf9cd5111aac9a8ec Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 27 Sep 2019 15:27:39 +0100 Subject: [PATCH] refactor: addch() to mutt_window_addch() Encapsulate a curses function to reduce dependencies. --- curs_lib.c | 8 ++++---- edit.c | 22 +++++++++++----------- menu.c | 44 ++++++++++++++++++++++---------------------- mutt_window.c | 11 +++++++++++ mutt_window.h | 14 +++++++++----- pager.c | 12 ++++++------ progress.c | 3 ++- sidebar.c | 6 +++--- 8 files changed, 68 insertions(+), 52 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index 19c240a9f..995bb58e3 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -882,13 +882,13 @@ int mutt_multi_choice(const char *prompt, const char *letters) { // we have a single letter within parentheses mutt_curses_set_color(MT_COLOR_OPTIONS); - addch(cur[1]); + mutt_window_addch(cur[1]); prompt = cur + 3; } else { // we have a parenthesis followed by something else - addch(cur[0]); + mutt_window_addch(cur[0]); prompt = cur + 1; } } @@ -898,7 +898,7 @@ int mutt_multi_choice(const char *prompt, const char *letters) addstr(prompt); mutt_curses_set_color(MT_COLOR_NORMAL); - addch(' '); + mutt_window_addch(' '); mutt_window_clrtoeol(MuttMessageWindow); } @@ -1185,7 +1185,7 @@ void mutt_paddstr(int n, const char *s) } } while (n-- > 0) - addch(' '); + mutt_window_addch(' '); } /** diff --git a/edit.c b/edit.c index c2d55d940..159785c30 100644 --- a/edit.c +++ b/edit.c @@ -175,7 +175,7 @@ static int be_barf_file(const char *path, char **buf, int buflen) if (!fp) { addstr(strerror(errno)); - addch('\n'); + mutt_window_addch('\n'); return -1; } for (int i = 0; i < buflen; i++) @@ -277,7 +277,7 @@ static void be_print_header(struct Envelope *env) tmp[0] = '\0'; mutt_addrlist_write(tmp, sizeof(tmp), &env->to, true); addstr(tmp); - addch('\n'); + mutt_window_addch('\n'); } if (!TAILQ_EMPTY(&env->cc)) { @@ -285,7 +285,7 @@ static void be_print_header(struct Envelope *env) tmp[0] = '\0'; mutt_addrlist_write(tmp, sizeof(tmp), &env->cc, true); addstr(tmp); - addch('\n'); + mutt_window_addch('\n'); } if (!TAILQ_EMPTY(&env->bcc)) { @@ -293,15 +293,15 @@ static void be_print_header(struct Envelope *env) tmp[0] = '\0'; mutt_addrlist_write(tmp, sizeof(tmp), &env->bcc, true); addstr(tmp); - addch('\n'); + mutt_window_addch('\n'); } if (env->subject) { addstr("Subject: "); addstr(env->subject); - addch('\n'); + mutt_window_addch('\n'); } - addch('\n'); + mutt_window_addch('\n'); } /** @@ -337,7 +337,7 @@ static void be_edit_header(struct Envelope *e, bool force) mutt_addrlist_to_intl(&e->to, NULL); /* XXX - IDNA error reporting? */ addstr(tmp); } - addch('\n'); + mutt_window_addch('\n'); if (!e->subject || force) { @@ -345,7 +345,7 @@ static void be_edit_header(struct Envelope *e, bool force) mutt_str_strfcpy(tmp, e->subject ? e->subject : "", sizeof(tmp)); if (mutt_enter_string(tmp, sizeof(tmp), 9, MUTT_COMP_NO_FLAGS) == 0) mutt_str_replace(&e->subject, tmp); - addch('\n'); + mutt_window_addch('\n'); } if ((TAILQ_EMPTY(&e->cc) && C_Askcc) || force) @@ -366,7 +366,7 @@ static void be_edit_header(struct Envelope *e, bool force) } else mutt_addrlist_to_intl(&e->cc, NULL); - addch('\n'); + mutt_window_addch('\n'); } if (C_Askbcc || force) @@ -387,7 +387,7 @@ static void be_edit_header(struct Envelope *e, bool force) } else mutt_addrlist_to_intl(&e->bcc, NULL); - addch('\n'); + mutt_window_addch('\n'); } } @@ -424,7 +424,7 @@ int mutt_builtin_editor(const char *path, struct Email *e_new, struct Email *e_c tmp[0] = '\0'; continue; } - addch('\n'); + mutt_window_addch('\n'); if (C_Escape && (tmp[0] == C_Escape[0]) && (tmp[1] != C_Escape[0])) { diff --git a/menu.c b/menu.c index a49467f56..c1fd1b4e5 100644 --- a/menu.c +++ b/menu.c @@ -167,7 +167,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do { case MUTT_TREE_LLCORNER: if (C_AsciiChars) - addch('`'); + mutt_window_addch('`'); #ifdef WACS_LLCORNER else add_wch(WACS_LLCORNER); @@ -175,12 +175,12 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do else if (CharsetIsUtf8) addstr("\342\224\224"); /* WACS_LLCORNER */ else - addch(ACS_LLCORNER); + mutt_window_addch(ACS_LLCORNER); #endif break; case MUTT_TREE_ULCORNER: if (C_AsciiChars) - addch(','); + mutt_window_addch(','); #ifdef WACS_ULCORNER else add_wch(WACS_ULCORNER); @@ -188,12 +188,12 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do else if (CharsetIsUtf8) addstr("\342\224\214"); /* WACS_ULCORNER */ else - addch(ACS_ULCORNER); + mutt_window_addch(ACS_ULCORNER); #endif break; case MUTT_TREE_LTEE: if (C_AsciiChars) - addch('|'); + mutt_window_addch('|'); #ifdef WACS_LTEE else add_wch(WACS_LTEE); @@ -201,12 +201,12 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do else if (CharsetIsUtf8) addstr("\342\224\234"); /* WACS_LTEE */ else - addch(ACS_LTEE); + mutt_window_addch(ACS_LTEE); #endif break; case MUTT_TREE_HLINE: if (C_AsciiChars) - addch('-'); + mutt_window_addch('-'); #ifdef WACS_HLINE else add_wch(WACS_HLINE); @@ -214,12 +214,12 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do else if (CharsetIsUtf8) addstr("\342\224\200"); /* WACS_HLINE */ else - addch(ACS_HLINE); + mutt_window_addch(ACS_HLINE); #endif break; case MUTT_TREE_VLINE: if (C_AsciiChars) - addch('|'); + mutt_window_addch('|'); #ifdef WACS_VLINE else add_wch(WACS_VLINE); @@ -227,12 +227,12 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do else if (CharsetIsUtf8) addstr("\342\224\202"); /* WACS_VLINE */ else - addch(ACS_VLINE); + mutt_window_addch(ACS_VLINE); #endif break; case MUTT_TREE_TTEE: if (C_AsciiChars) - addch('-'); + mutt_window_addch('-'); #ifdef WACS_TTEE else add_wch(WACS_TTEE); @@ -240,12 +240,12 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do else if (CharsetIsUtf8) addstr("\342\224\254"); /* WACS_TTEE */ else - addch(ACS_TTEE); + mutt_window_addch(ACS_TTEE); #endif break; case MUTT_TREE_BTEE: if (C_AsciiChars) - addch('-'); + mutt_window_addch('-'); #ifdef WACS_BTEE else add_wch(WACS_BTEE); @@ -253,26 +253,26 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do else if (CharsetIsUtf8) addstr("\342\224\264"); /* WACS_BTEE */ else - addch(ACS_BTEE); + mutt_window_addch(ACS_BTEE); #endif break; case MUTT_TREE_SPACE: - addch(' '); + mutt_window_addch(' '); break; case MUTT_TREE_RARROW: - addch('>'); + mutt_window_addch('>'); break; case MUTT_TREE_STAR: - addch('*'); /* fake thread indicator */ + mutt_window_addch('*'); /* fake thread indicator */ break; case MUTT_TREE_HIDDEN: - addch('&'); + mutt_window_addch('&'); break; case MUTT_TREE_EQUALS: - addch('='); + mutt_window_addch('='); break; case MUTT_TREE_MISSING: - addch('?'); + mutt_window_addch('?'); break; } s++; @@ -441,7 +441,7 @@ void menu_redraw_index(struct Menu *menu) { addstr("->"); mutt_curses_set_attr(attr); - addch(' '); + mutt_window_addch(' '); } else do_color = false; @@ -537,7 +537,7 @@ void menu_redraw_current(struct Menu *menu) { addstr("->"); mutt_curses_set_attr(attr); - addch(' '); + mutt_window_addch(' '); menu_pad_string(menu, buf, sizeof(buf)); print_enriched_string(menu->current, attr, (unsigned char *) buf, true); } diff --git a/mutt_window.c b/mutt_window.c index 11dbcfc0f..65f4fea69 100644 --- a/mutt_window.c +++ b/mutt_window.c @@ -343,3 +343,14 @@ int mutt_window_wrap_cols(int width, short wrap) else return width; } + +/** + * mutt_window_addch - Write one character to a Window + * @param ch Character to write + * @retval 0 Success + * @retval -1 Error + */ +int mutt_window_addch(int ch) +{ + return addch(ch); +} diff --git a/mutt_window.h b/mutt_window.h index 5668cb25c..4cb613ab9 100644 --- a/mutt_window.h +++ b/mutt_window.h @@ -46,19 +46,23 @@ extern struct MuttWindow *MuttSidebarWindow; #endif extern struct MuttWindow *MuttStatusWindow; -void mutt_window_clearline (struct MuttWindow *win, int row); -void mutt_window_clrtoeol (struct MuttWindow *win); +// Functions that deal with the Window void mutt_window_copy_size (const struct MuttWindow *win_src, struct MuttWindow *win_dst); void mutt_window_free (struct MuttWindow **ptr); void mutt_window_free_all (void); void mutt_window_getxy (struct MuttWindow *win, int *x, int *y); void mutt_window_init (void); -int mutt_window_move (struct MuttWindow *win, 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, ...); struct MuttWindow *mutt_window_new (void); void mutt_window_reflow (void); void mutt_window_reflow_message_rows(int mw_rows); int mutt_window_wrap_cols (int width, short wrap); +// Functions for drawing on the Window +int mutt_window_addch (int ch); +void mutt_window_clearline(struct MuttWindow *win, int row); +void mutt_window_clrtoeol (struct MuttWindow *win); +int mutt_window_move (struct MuttWindow *win, 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, ...); + #endif /* MUTT_MUTT_WINDOW_H */ diff --git a/pager.c b/pager.c index f46c574e3..abba13847 100644 --- a/pager.c +++ b/pager.c @@ -377,7 +377,7 @@ static void resolve_color(struct Line *line_info, int n, int cnt, if (!cnt && C_Markers) { mutt_curses_set_color(MT_COLOR_MARKERS); - addch('+'); + mutt_window_addch('+'); last_color = ColorDefs[MT_COLOR_MARKERS]; } m = (line_info[n].syntax)[0].first; @@ -1576,7 +1576,7 @@ static int format_line(struct Line **line_info, int n, unsigned char *buf, break; if (pa) for (; col < t; col++) - addch(' '); + mutt_window_addch(' '); else col = t; } @@ -1602,7 +1602,7 @@ static int format_line(struct Line **line_info, int n, unsigned char *buf, break; col += k; if (pa) - addch(ReplacementChar); + mutt_window_addch(ReplacementChar); } } *pspace = space; @@ -1856,7 +1856,7 @@ static int display_line(FILE *fp, LOFF_T *last_pos, struct Line **line_info, if (col == 0) { mutt_curses_set_color(MT_COLOR_NORMAL); - addch(' '); + mutt_window_addch(' '); } #endif @@ -1865,7 +1865,7 @@ static int display_line(FILE *fp, LOFF_T *last_pos, struct Line **line_info, resolve_color(*line_info, n, vch, flags, 0, &a); /* Fill the blank space at the end of the line with the prevailing color. - * ncurses does an implicit clrtoeol() when you do addch('\n') so we have + * ncurses does an implicit clrtoeol() when you do mutt_window_addch('\n') so we have * to make sure to reset the color *after* that */ if (flags & MUTT_SHOWCOLOR) { @@ -2139,7 +2139,7 @@ static void pager_custom_redraw(struct Menu *pager_menu) { mutt_window_clrtoeol(rd->pager_window); if (C_Tilde) - addch('~'); + mutt_window_addch('~'); rd->lines++; mutt_window_move(rd->pager_window, rd->lines, 0); } diff --git a/progress.c b/progress.c index 281a08704..671a4795f 100644 --- a/progress.c +++ b/progress.c @@ -37,6 +37,7 @@ #include "curs_lib.h" #include "mutt_curses.h" #include "mutt_logging.h" +#include "mutt_window.h" #include "muttlib.h" #include "options.h" @@ -86,7 +87,7 @@ static void message_bar(int percent, const char *fmt, ...) w -= l; while (w-- > 0) { - addch(' '); + mutt_window_addch(' '); } mutt_curses_set_color(MT_COLOR_NORMAL); } diff --git a/sidebar.c b/sidebar.c index 7a12ff697..e4002fcf8 100644 --- a/sidebar.c +++ b/sidebar.c @@ -761,10 +761,10 @@ static int draw_divider(int num_rows, int num_cols) addstr(NONULL(C_SidebarDividerChar)); break; case SB_DIV_ASCII: - addch('|'); + mutt_window_addch('|'); break; case SB_DIV_UTF8: - addch(ACS_VLINE); + mutt_window_addch(ACS_VLINE); break; } } @@ -793,7 +793,7 @@ static void fill_empty_space(int first_row, int num_rows, int div_width, int num mutt_window_move(MuttSidebarWindow, first_row + r, div_width); for (int i = 0; i < num_cols; i++) - addch(' '); + mutt_window_addch(' '); } } -- 2.40.0