X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-ui%2Fenter.c;h=8fe60edf54403db67ba3a7ce9a0d1a7d1403a018;hp=39e0100f29fb1e46f9c153f4c0f6a93b07e1d76a;hb=HEAD;hpb=230399f9632c37b66c1c117a17e8327eae6b3235 diff --git a/lib-ui/enter.c b/lib-ui/enter.c index 39e0100..8fe60ed 100644 --- a/lib-ui/enter.c +++ b/lib-ui/enter.c @@ -8,18 +8,10 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - -#include +#include -#include "curses.h" -#include "enter.h" #include "menu.h" +#include "browser.h" #include "mutt.h" #include "alias.h" @@ -27,6 +19,15 @@ #include "history.h" #include "buffy.h" +typedef struct { + wchar_t *wbuf; + size_t wbuflen; + size_t lastchar; + size_t curpos; + size_t begin; + int tabs; +} ENTER_STATE; + /* redraw flags for mutt_enter_string() */ enum { M_REDRAW_INIT = 1, /* go to end of line and redraw */ @@ -63,12 +64,12 @@ static int my_addwch (wchar_t wc) int n = wcwidth (wc); if (iswprint(wc) && n > 0) - return mutt_addwch (wc); + return waddwch(stdscr, wc); if (!(wc & ~0x7f)) - return printw ("^%c", ((int) wc + 0x40) & 0x7f); + return wprintw (stdscr, "^%c", ((int) wc + 0x40) & 0x7f); if (!(wc & ~0xffff)) - return printw ("\\u%04x", (int) wc); - return printw ("\\u%08x", (int) wc); + return wprintw (stdscr, "\\u%04x", (int) wc); + return wprintw (stdscr, "\\u%08x", (int) wc); } static size_t width_ceiling (const wchar_t * s, size_t n, int w1) @@ -122,7 +123,7 @@ static void my_wcstombs (char *dest, ssize_t dlen, const wchar_t * src, } } -size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, const char *buf) +static size_t my_mbstowcs (wchar_t ** pwbuf, size_t * pwbuflen, size_t i, const char *buf) { wchar_t wc; mbstate_t st; @@ -172,26 +173,10 @@ static void replace_part (ENTER_STATE *state, size_t from, const char *buf) p_delete(&savebuf); } -/* - * Returns: - * 1 need to redraw the screen and call me again - * 0 if input was given - * -1 if abort. - */ - -int mutt_enter_string (char *buf, size_t buflen, int y, int x, int flags) -{ - int rv; - ENTER_STATE *es = mutt_new_enter_state (); - - rv = _mutt_enter_string (buf, buflen, y, x, flags, 0, NULL, NULL, es); - mutt_free_enter_state (&es); - return rv; -} - -int _mutt_enter_string (char *buf, size_t buflen, int y, int x, - int flags, int multiple, char ***files, int *numfiles, - ENTER_STATE * state) +static int +mutt_enter_string(char *buf, size_t buflen, int y, int x, int flags, + int multiple, char ***files, int *numfiles, + ENTER_STATE *state) { int width = COLS - x - 1; int redraw; @@ -250,7 +235,7 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, width_ceiling (state->wbuf, state->lastchar, my_wcswidth (state->wbuf, state->curpos) - width / 2); - move (y, x); + wmove (stdscr, y, x); w = 0; for (i = state->begin; i < state->lastchar; i++) { w += my_wcwidth (state->wbuf[i]); @@ -258,10 +243,10 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, break; my_addwch (state->wbuf[i]); } - clrtoeol (); - move (y, - x + my_wcswidth (state->wbuf + state->begin, - state->curpos - state->begin)); + wclrtoeol (stdscr); + wmove (stdscr, y, + x + my_wcswidth (state->wbuf + state->begin, + state->curpos - state->begin)); } mutt_refresh (); @@ -462,8 +447,8 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, if (tempbuf && templen == state->lastchar - i && !memcmp (tempbuf, state->wbuf + i, (state->lastchar - i) * sizeof (wchar_t))) { - mutt_select_file (buf, buflen, - (flags & M_EFILE) ? M_SEL_FOLDER : 0); + mutt_select_file(buf, buflen, flags & M_EFILE ? M_SEL_FOLDER : 0, + NULL, NULL); set_option (OPTNEEDREDRAW); if (*buf) replace_part (state, i, buf); @@ -521,9 +506,9 @@ int _mutt_enter_string (char *buf, size_t buflen, int y, int x, || (tempbuf && templen == state->lastchar && !memcmp (tempbuf, state->wbuf, state->lastchar * sizeof (wchar_t)))) { - _mutt_select_file (buf, buflen, - ((flags & M_EFILE) ? M_SEL_FOLDER : 0) | - (multiple ? M_SEL_MULTI : 0), files, numfiles); + mutt_select_file(buf, buflen, + ((flags & M_EFILE) ? M_SEL_FOLDER : 0) | + (multiple ? M_SEL_MULTI : 0), files, numfiles); set_option (OPTNEEDREDRAW); if (*buf) { mutt_pretty_mailbox (buf); @@ -670,13 +655,27 @@ bye: return rv; } -void mutt_free_enter_state (ENTER_STATE ** esp) +int _mutt_get_field(const char *field, char *buf, ssize_t buflen, int flags, + int multiple, char ***files, int *numfiles) { - if (!esp) - return; + int ret; + int x, y; + ENTER_STATE es; - p_delete(&(*esp)->wbuf); - p_delete(esp); + p_clear(&es, 1); + + do { + CLEARLINE(stdscr, LINES - 1); + waddstr (stdscr, field); + mutt_refresh (); + getyx (stdscr, y, x); + ret = mutt_enter_string(buf, buflen, y, x, flags, multiple, files, + numfiles, &es); + } while (ret == 1); + CLEARLINE(stdscr, LINES - 1); + + p_delete(&es.wbuf); + return ret; } /*