From: Richard Russon Date: Fri, 27 Sep 2019 14:36:19 +0000 (+0100) Subject: refactor: addnstr() to mutt_window_addnstr() X-Git-Tag: 2019-10-25~30^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28b19b2932397723d435f399ef782a593fe75050;p=neomutt refactor: addnstr() to mutt_window_addnstr() Encapsulate a curses function to reduce dependencies. --- diff --git a/curs_lib.c b/curs_lib.c index 995bb58e3..7e2a69680 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -403,7 +403,7 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def) mutt_window_move(MuttMessageWindow, 0, 0); mutt_curses_set_color(MT_COLOR_PROMPT); - addnstr(msg, trunc_msg_len); + mutt_window_addnstr(msg, trunc_msg_len); addstr(answer_string); mutt_curses_set_color(MT_COLOR_NORMAL); mutt_window_clrtoeol(MuttMessageWindow); @@ -876,7 +876,7 @@ int mutt_multi_choice(const char *prompt, const char *letters) { // write the part between prompt and cur using MT_COLOR_PROMPT mutt_curses_set_color(MT_COLOR_PROMPT); - addnstr(prompt, cur - prompt); + mutt_window_addnstr(prompt, cur - prompt); if (isalnum(cur[1]) && (cur[2] == ')')) { @@ -1180,7 +1180,7 @@ void mutt_paddstr(int n, const char *s) { if (w > n) break; - addnstr((char *) s, k); + mutt_window_addnstr((char *) s, k); n -= w; } } diff --git a/index.c b/index.c index 3143c9a9c..c59d2a51e 100644 --- a/index.c +++ b/index.c @@ -920,7 +920,7 @@ void mutt_draw_statusline(int cols, const char *buf, size_t buflen) if ((chunks > 0) && (syntax[0].first > 0)) { /* Text before the first highlight */ - addnstr(buf, MIN(len, syntax[0].first)); + mutt_window_addnstr(buf, MIN(len, syntax[0].first)); attrset(ColorDefs[MT_COLOR_STATUS]); if (len <= syntax[0].first) goto dsl_finish; /* no more room */ @@ -932,7 +932,7 @@ void mutt_draw_statusline(int cols, const char *buf, size_t buflen) { /* Highlighted text */ attrset(syntax[i].color); - addnstr(buf + offset, MIN(len, syntax[i].last) - offset); + mutt_window_addnstr(buf + offset, MIN(len, syntax[i].last) - offset); if (len <= syntax[i].last) goto dsl_finish; /* no more room */ @@ -948,7 +948,7 @@ void mutt_draw_statusline(int cols, const char *buf, size_t buflen) attrset(ColorDefs[MT_COLOR_STATUS]); offset = syntax[i].last; - addnstr(buf + offset, next - offset); + mutt_window_addnstr(buf + offset, next - offset); offset = next; if (offset >= len) @@ -959,7 +959,7 @@ void mutt_draw_statusline(int cols, const char *buf, size_t buflen) if (offset < len) { /* Text after the last highlight */ - addnstr(buf + offset, len - offset); + mutt_window_addnstr(buf + offset, len - offset); } int width = mutt_strwidth(buf); diff --git a/menu.c b/menu.c index c1fd1b4e5..6bf1d2ebc 100644 --- a/menu.c +++ b/menu.c @@ -307,7 +307,7 @@ static void print_enriched_string(int index, int attr, unsigned char *s, bool do } else if ((k = mbrtowc(&wc, (char *) s, n, &mbstate)) > 0) { - addnstr((char *) s, k); + mutt_window_addnstr((char *) s, k); s += k; n -= k; } diff --git a/mutt_curses.h b/mutt_curses.h index 89b1bd26e..8af1918c3 100644 --- a/mutt_curses.h +++ b/mutt_curses.h @@ -49,13 +49,11 @@ /* The prototypes for these four functions use "(char*)", * whereas the ncurses versions use "(const char*)" */ -#undef addnstr #undef addstr #undef mvaddnstr #undef mvaddstr /* We redefine the helper macros to hide the compiler warnings */ -#define addnstr(str, n) waddnstr(stdscr, ((char *) str), (n)) #define addstr(x) waddstr(stdscr, ((char *) x)) #define mvaddnstr(y, x, str, n) mvwaddnstr(stdscr, (y), (x), ((char *) str), (n)) #define mvaddstr(y, x, str) mvwaddstr(stdscr, (y), (x), ((char *) str)) diff --git a/mutt_window.c b/mutt_window.c index 65f4fea69..59fa74605 100644 --- a/mutt_window.c +++ b/mutt_window.c @@ -354,3 +354,22 @@ int mutt_window_addch(int ch) { return addch(ch); } + +/** + * mutt_window_addnstr - Write a partial string to a Window + * @param str String + * @param num Maximum number of characters to write + * @retval 0 Success + * @retval -1 Error + */ +int mutt_window_addnstr(const char *str, int num) +{ + if (!str) + return -1; + +#ifdef USE_SLANG_CURSES + return addnstr((char *) str, num); +#else + return addnstr(str, num); +#endif +} diff --git a/mutt_window.h b/mutt_window.h index 4cb613ab9..49eb6d0e4 100644 --- a/mutt_window.h +++ b/mutt_window.h @@ -59,6 +59,7 @@ int mutt_window_wrap_cols (int width, short wrap); // Functions for drawing on the Window int mutt_window_addch (int ch); +int mutt_window_addnstr (const char *str, int num); 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);