From: Kevin McCarthy Date: Sun, 16 Apr 2017 21:38:40 +0000 (-0700) Subject: Add multiline and sigwinch handling to mutt_yesorno. (closes #3877) X-Git-Tag: neomutt-20170421~12^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ca9bf48592bae81db0b063450b363b6817bff93d;p=neomutt Add multiline and sigwinch handling to mutt_yesorno. (closes #3877) Most of the yes/no and query_quadoption prompts are pretty short, but for completeness add handling for those too. --- diff --git a/curs_lib.c b/curs_lib.c index 1a54206ce..c4dca0be1 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -71,6 +71,9 @@ mutt_window_t *MuttMessageWindow = NULL; mutt_window_t *MuttSidebarWindow = NULL; #endif +static void reflow_message_window_rows(int mw_rows); + + void mutt_refresh(void) { /* don't refresh when we are waiting for a child. */ @@ -228,8 +231,9 @@ int mutt_yesorno(const char *msg, int def) char *yes = _("yes"); char *no = _("no"); char *answer_string = NULL; - size_t answer_string_len; - size_t msglen; + int answer_string_wid, msg_wid; + size_t trunc_msg_len; + int redraw = 1, prompt_lines = 1; #ifdef HAVE_LANGINFO_YESEXPR char *expr = NULL; @@ -247,8 +251,6 @@ int mutt_yesorno(const char *msg, int def) !REGCOMP(&reno, expr, REG_NOSUB); #endif - mutt_window_clearline(MuttMessageWindow, 0); - /* * In order to prevent the default answer to the question to wrapped * around the screen in the even the question is wider than the screen, @@ -257,20 +259,55 @@ int mutt_yesorno(const char *msg, int def) */ safe_asprintf(&answer_string, " ([%s]/%s): ", def == MUTT_YES ? yes : no, def == MUTT_YES ? no : yes); - answer_string_len = mutt_strwidth(answer_string); - /* maxlen here is sort of arbitrary, so pick a reasonable upper bound */ - msglen = mutt_wstr_trunc(msg, 4 * MuttMessageWindow->cols, - MuttMessageWindow->cols - answer_string_len, NULL); - SETCOLOR(MT_COLOR_PROMPT); - addnstr(msg, msglen); - addstr(answer_string); - NORMAL_COLOR; - FREE(&answer_string); + answer_string_wid = mutt_strwidth(answer_string); + msg_wid = mutt_strwidth(msg); while (true) { + if (redraw || SigWinch) + { + redraw = 0; +#if defined(USE_SLANG_CURSES) || defined(HAVE_RESIZETERM) + if (SigWinch) + { + SigWinch = 0; + mutt_resize_screen(); + clearok(stdscr, TRUE); + mutt_current_menu_redraw(); + } +#endif + if (MuttMessageWindow->cols) + { + prompt_lines = (msg_wid + answer_string_wid + MuttMessageWindow->cols - 1) / + MuttMessageWindow->cols; + prompt_lines = MAX(1, MIN(3, prompt_lines)); + } + if (prompt_lines != MuttMessageWindow->rows) + { + reflow_message_window_rows(prompt_lines); + mutt_current_menu_redraw(); + } + + /* maxlen here is sort of arbitrary, so pick a reasonable upper bound */ + trunc_msg_len = mutt_wstr_trunc( + msg, 4 * prompt_lines * MuttMessageWindow->cols, + prompt_lines * MuttMessageWindow->cols - answer_string_wid, NULL); + + mutt_window_move(MuttMessageWindow, 0, 0); + SETCOLOR(MT_COLOR_PROMPT); + addnstr(msg, trunc_msg_len); + addstr(answer_string); + NORMAL_COLOR; + mutt_window_clrtoeol(MuttMessageWindow); + } + mutt_refresh(); + /* SigWinch is not processed unless timeout is set */ + timeout(30 * 1000); ch = mutt_getch(); + timeout(-1); + if (ch.ch == -2) + continue; if (CI_is_return(ch.ch)) break; if (ch.ch < 0) @@ -305,6 +342,8 @@ int mutt_yesorno(const char *msg, int def) } } + FREE(&answer_string); + #ifdef HAVE_LANGINFO_YESEXPR if (reyes_ok) regfree(&reyes); @@ -312,6 +351,14 @@ int mutt_yesorno(const char *msg, int def) regfree(&reno); #endif + if (MuttMessageWindow->rows != 1) + { + reflow_message_window_rows(1); + mutt_current_menu_redraw(); + } + else + mutt_window_clearline(MuttMessageWindow, 0); + if (def != MUTT_ABORT) { addstr((char *) (def == MUTT_YES ? yes : no));