Skip to content

Commit

Permalink
Create mutt_buffer_get_field()
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kevin8t8 and flatcap committed Oct 1, 2019
1 parent 17ef29b commit c5a42f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
42 changes: 37 additions & 5 deletions curs_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions curs_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c5a42f8

Please sign in to comment.