]> granicus.if.org Git - mutt/commitdiff
do not use mutt_message() to display prompt in mutt_yesorno().
authorMichael Elkins <me@sigpipe.org>
Thu, 31 Jan 2013 05:06:56 +0000 (05:06 +0000)
committerMichael Elkins <me@sigpipe.org>
Thu, 31 Jan 2013 05:06:56 +0000 (05:06 +0000)
properly calculate screen width of prompt string by using mutt_strwidth() rather than strlen()

use safe_asprintf() return the formatted yes/no string since specifying COLS+1 is wrong when dealing with multibyte characters

closes #3412
closes #3352

curs_lib.c

index c7a7676e62d1c2827e14de20c3e481b651397235..3beb0e30eacfb023f7ff648a51724f49f5f5b40b 100644 (file)
@@ -195,6 +195,7 @@ int mutt_yesorno (const char *msg, int def)
   char *no = _("no");
   char *answer_string;
   size_t answer_string_len;
+  size_t msglen;
 
 #ifdef HAVE_LANGINFO_YESEXPR
   char *expr;
@@ -220,10 +221,12 @@ int mutt_yesorno (const char *msg, int def)
    * ensure there is enough room for the answer and truncate the question
    * to fit.
    */
-  answer_string = safe_malloc (COLS + 1);
-  snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no, def == M_YES ? no : yes);
-  answer_string_len = strlen (answer_string);
-  mutt_message ("%.*s%s", COLS - answer_string_len, msg, answer_string);
+  safe_asprintf (&answer_string, " ([%s]/%s): ", def == M_YES ? yes : no, def == M_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*COLS, COLS - answer_string_len, NULL);
+  addnstr (msg, msglen);
+  addstr (answer_string);
   FREE (&answer_string);
 
   FOREVER