]> granicus.if.org Git - neomutt/commitdiff
Create mutt_buffer_get_field()
authorKevin McCarthy <kevin@8t8.us>
Sun, 22 Sep 2019 21:11:43 +0000 (14:11 -0700)
committerRichard Russon <rich@flatcap.org>
Tue, 1 Oct 2019 10:25:08 +0000 (11:25 +0100)
This will reduce the buffer->dptr fiddling all over the place into one
spot until mutt_enter_string() can be converted.

Co-authored-by: Richard Russon <rich@flatcap.org>
curs_lib.c
curs_lib.h

index a11b282b935db8f47189e9a89ddb67d69bf7cebe..1f4b6b9c869b9a52662af63c21a61ceb59d37695 100644 (file)
@@ -242,10 +242,9 @@ struct KeyEvent mutt_getch(void)
 }
 
 /**
- * mutt_get_field_full - Ask the user for a string
+ * mutt_buffer_get_field_full - Ask the user for a string
  * @param[in]  field    Prompt
  * @param[in]  buf      Buffer for the result
- * @param[in]  buflen   Length of buffer
  * @param[in]  complete Flags, see #CompletionFlags
  * @param[in]  multiple Allow multiple selections
  * @param[out] files    List of files selected
@@ -254,8 +253,8 @@ struct KeyEvent mutt_getch(void)
  * @retval 0  Selection made
  * @retval -1 Aborted
  */
-int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionFlags complete,
-                        bool multiple, char ***files, int *numfiles)
+int mutt_buffer_get_field_full(const char *field, struct Buffer *buf, CompletionFlags complete,
+                               bool multiple, char ***files, int *numfiles)
 {
   int ret;
   int col;
@@ -277,14 +276,47 @@ int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionF
     mutt_curses_set_color(MT_COLOR_NORMAL);
     mutt_refresh();
     mutt_window_get_coords(MuttMessageWindow, NULL, &col);
-    ret = mutt_enter_string_full(buf, buflen, col, complete, multiple, files, numfiles, es);
+    ret = mutt_enter_string_full(buf->data, buf->dsize, col, complete, multiple,
+                                 files, numfiles, es);
   } while (ret == 1);
+
+  if (ret != 0)
+    mutt_buffer_reset(buf);
+  else
+    mutt_buffer_fix_dptr(buf);
+
   mutt_window_clearline(MuttMessageWindow, 0);
   mutt_enter_state_free(&es);
 
   return ret;
 }
 
+/**
+ * mutt_get_field_full - Ask the user for a string
+ * @param[in]  field    Prompt
+ * @param[in]  buf      Buffer for the result
+ * @param[in]  buflen   Length of buffer
+ * @param[in]  complete Flags, see #CompletionFlags
+ * @param[in]  multiple Allow multiple selections
+ * @param[out] files    List of files selected
+ * @param[out] numfiles Number of files selected
+ * @retval 1  Redraw the screen and call the function again
+ * @retval 0  Selection made
+ * @retval -1 Aborted
+ */
+int mutt_get_field_full(const char *field, char *buf, size_t buflen, CompletionFlags complete,
+                        bool multiple, char ***files, int *numfiles)
+{
+  struct Buffer *tmp = mutt_buffer_pool_get();
+
+  mutt_buffer_addstr(tmp, buf);
+  int rc = mutt_buffer_get_field_full(field, tmp, complete, multiple, files, numfiles);
+  mutt_str_strfcpy(buf, mutt_b2s(tmp), buflen);
+
+  mutt_buffer_pool_release(&tmp);
+  return rc;
+}
+
 /**
  * mutt_get_field_unbuffered - Ask the user for a string (ignoring macro buffer)
  * @param msg    Prompt
index 27624073ccb425b57a9c5f2efaf053ba78b86950..ca7d6f76bec2502cbbbc5a09e1817bb11947c3c2 100644 (file)
@@ -81,6 +81,9 @@ void         mutt_unget_string(const char *s);
 size_t       mutt_wstr_trunc(const char *src, size_t maxlen, size_t maxwid, size_t *width);
 enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def);
 
+#define mutt_buffer_get_field(field, buf, complete) mutt_buffer_get_field_full(field, buf, complete, 0, NULL, NULL)
+int mutt_buffer_get_field_full(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, char ***files, int *numfiles);
+
 #define mutt_buffer_enter_fname(prompt, fname, mailbox) mutt_buffer_enter_fname_full(prompt, fname, mailbox, false, NULL, NULL, MUTT_SEL_NO_FLAGS)
 int mutt_buffer_enter_fname_full(const char *prompt, struct Buffer *fname, bool mailbox, bool multiple, char ***files, int *numfiles, SelectFileFlags flags);