]> granicus.if.org Git - neomutt/commitdiff
refactor: addnstr() to mutt_window_addnstr()
authorRichard Russon <rich@flatcap.org>
Fri, 27 Sep 2019 14:36:19 +0000 (15:36 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 28 Sep 2019 02:18:27 +0000 (03:18 +0100)
Encapsulate a curses function to reduce dependencies.

curs_lib.c
index.c
menu.c
mutt_curses.h
mutt_window.c
mutt_window.h

index 995bb58e39f190794a90b1b9c9a09e2780d71a31..7e2a69680f803a3b39ca80e542f9384cc6668dcb 100644 (file)
@@ -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 3143c9a9c7732da8415604c41f40394f271776d3..c59d2a51e37701efb735a59e311cb82a09df3a2c 100644 (file)
--- 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 c1fd1b4e5178d7869c383ab61d94f8b9000ac038..6bf1d2ebc6ab77c6887340fb1f7bbdd498894210 100644 (file)
--- 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;
     }
index 89b1bd26e78cb4ecf99e27d97cd691f9a7ff1f7a..8af1918c38adedf512c3f6e01b9f49e10cad1137 100644 (file)
 
 /* 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))
index 65f4fea6965deda309b25583ec47a10afbf3db8c..59fa746053fe3fe2f75bc71b1df12513d16c2971 100644 (file)
@@ -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
+}
index 4cb613ab92f5561c0aa3a08ab7a312fe7b041f6e..49eb6d0e47895ebaf8a83a279364fec45d20e215 100644 (file)
@@ -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);