From: Kevin McCarthy Date: Sun, 22 Sep 2019 21:11:43 +0000 (-0700) Subject: Create mutt_buffer_get_field() X-Git-Tag: 2019-10-25~23^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c5a42f8a72aca7fbf9246abc03b6fca87b10941a;p=neomutt Create mutt_buffer_get_field() 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 --- diff --git a/curs_lib.c b/curs_lib.c index a11b282b9..1f4b6b9c8 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -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 diff --git a/curs_lib.h b/curs_lib.h index 27624073c..ca7d6f76b 100644 --- a/curs_lib.h +++ b/curs_lib.h @@ -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);