]> granicus.if.org Git - neomutt/commitdiff
Add multiline and sigwinch handling to mutt_yesorno. (closes #3877)
authorKevin McCarthy <kevin@8t8.us>
Sun, 16 Apr 2017 21:38:40 +0000 (14:38 -0700)
committerKevin McCarthy <kevin@8t8.us>
Sun, 16 Apr 2017 21:38:40 +0000 (14:38 -0700)
Most of the yes/no and query_quadoption prompts are pretty short, but
for completeness add handling for those too.

curs_lib.c

index efe60e94b9079bef6f463e6489c0132df5ec041a..952f1f1fc257bf6d4f23b9415a1fe50d5b3c37d2 100644 (file)
@@ -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. */
@@ -229,8 +232,9 @@ int mutt_yesorno (const char *msg, int def)
   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 @@ 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,19 +259,55 @@ int mutt_yesorno (const char *msg, int def)
    * 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 @@ int mutt_yesorno (const char *msg, int def)
     }
   }
 
+  FREE (&answer_string);
+
 #ifdef HAVE_LANGINFO_YESEXPR    
   if (reyes_ok)
     regfree (& reyes);
@@ -313,6 +353,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 != -1)
   {
     addstr ((char *) (def == MUTT_YES ? yes : no));