]> granicus.if.org Git - neomutt/commitdiff
reflow multiline prompts correctly
authorRichard Russon <rich@flatcap.org>
Tue, 30 Jul 2019 12:57:33 +0000 (13:57 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 30 Jul 2019 19:10:22 +0000 (20:10 +0100)
When asking the user a long question, NeoMutt can expand the message
window up to three lines.

This fixes two problems with multiline prompts:

- `mutt_window_reflow()` was resizing the windows when it shouldn't

- coloured (shortened) prompts weren't being measured correctly
  (causing unnecessary wrapping)

curs_lib.c
index.c
menu.c
pager.c

index d5a8223a312b853b5bd619d3f638b24219aa6a03..79031cdcc5e2fff6ae60ecfd1fe377bc5547955e 100644 (file)
@@ -838,6 +838,9 @@ int mutt_multi_choice(const char *prompt, const char *letters)
   bool redraw = true;
   int prompt_lines = 1;
 
+  bool opt_cols = ((ColorDefs[MT_COLOR_OPTIONS] != 0) &&
+                   (ColorDefs[MT_COLOR_OPTIONS] != ColorDefs[MT_COLOR_PROMPT]));
+
   while (true)
   {
     if (redraw || SigWinch)
@@ -852,8 +855,13 @@ int mutt_multi_choice(const char *prompt, const char *letters)
       }
       if (MuttMessageWindow->cols)
       {
-        prompt_lines = (mutt_strwidth(prompt) + MuttMessageWindow->cols - 1) /
-                       MuttMessageWindow->cols;
+        int width = mutt_strwidth(prompt) + 2; // + '?' + space
+        /* If we're going to colour the options,
+         * make an assumption about the modified prompt size. */
+        if (opt_cols)
+          width -= 2 * mutt_str_strlen(letters);
+
+        prompt_lines = (width + MuttMessageWindow->cols - 1) / MuttMessageWindow->cols;
         prompt_lines = MAX(1, MIN(3, prompt_lines));
       }
       if (prompt_lines != MuttMessageWindow->rows)
diff --git a/index.c b/index.c
index c3c1b9ccb99b4479154cd7cfc93a1835cecb168a..f4911927641c0044b9dd7cb8b792865bcbc1d209 100644 (file)
--- a/index.c
+++ b/index.c
@@ -1043,6 +1043,7 @@ int mutt_index_menu(void)
                                      IndexHelp);
   menu->menu_custom_redraw = index_custom_redraw;
   mutt_menu_push_current(menu);
+  mutt_window_reflow();
 
   if (!attach_msg)
   {
diff --git a/menu.c b/menu.c
index 35736bb9cf50f77769c92da061ffde2536fa9abb..8d037b8f0fe06d7f457c83cb3254475be24f6fd3 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -358,7 +358,6 @@ static void menu_pad_string(struct Menu *menu, char *buf, size_t buflen)
  */
 void menu_redraw_full(struct Menu *menu)
 {
-  mutt_window_reflow();
   NORMAL_COLOR;
   /* clear() doesn't optimize screen redraws */
   move(0, 0);
diff --git a/pager.c b/pager.c
index 47f51924b1c7ceba889ee1292fda3061579205c6..2d7701278f26b856036b6d7b2d7e31701426bde8 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -1940,7 +1940,6 @@ static void pager_custom_redraw(struct Menu *pager_menu)
 
   if (pager_menu->redraw & REDRAW_FULL)
   {
-    mutt_window_reflow();
     NORMAL_COLOR;
     /* clear() doesn't optimize screen redraws */
     move(0, 0);