From 419b140777aff9080bb2cae939d84d3ef6774319 Mon Sep 17 00:00:00 2001 From: Michael Elkins Date: Thu, 31 Jan 2013 05:06:56 +0000 Subject: [PATCH] do not use mutt_message() to display prompt in mutt_yesorno(). 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 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index c7a7676e..3beb0e30 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -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 -- 2.40.0