changeset: 7010:61295113f7ab
user:      Kevin McCarthy <[email protected]>
date:      Sun Apr 16 14:38:40 2017 -0700
link:      http://dev.mutt.org/hg/mutt/rev/61295113f7ab

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.

diffs (122 lines):

diff -r 2be3dd383c35 -r 61295113f7ab curs_lib.c
--- a/curs_lib.c        Sat Apr 15 12:56:46 2017 -0700
+++ b/curs_lib.c        Sun Apr 16 14:38:40 2017 -0700
@@ -71,6 +71,9 @@
 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. */
@@ -229,8 +232,9 @@
   char *yes = _("yes");
   char *no = _("no");
   char *answer_string;
-  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;
@@ -248,8 +252,6 @@
             !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,19 +259,55 @@
    * to fit.
    */
   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);
 
   FOREVER
   {
+    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)
@@ -306,6 +344,8 @@
     }
   }
 
+  FREE (&answer_string);
+
 #ifdef HAVE_LANGINFO_YESEXPR    
   if (reyes_ok)
     regfree (& reyes);
@@ -313,6 +353,14 @@
     regfree (& reno);
 #endif
 
+  if (MuttMessageWindow->rows != 1)
+  {
+    reflow_message_window_rows (1);
+    mutt_current_menu_redraw ();
+  }
+  else
+    mutt_window_clearline (MuttMessageWindow, 0);
+
   if (def != -1)
   {
     addstr ((char *) (def == MUTT_YES ? yes : no));

Reply via email to