From 1903ace2759f48f8ca1f20febc7b468c5769f59d Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Fri, 24 Dec 2004 00:43:41 +0000
Subject: [PATCH] fix statusbar() and onekey() to properly handle multibyte
 strings too

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2196 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog   |  4 ++--
 src/winio.c | 20 ++++++++++++++------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0c079388..166ba782 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -56,8 +56,8 @@ CVS code -
 	  move_right(), and display_string_len(); changes to do_left(),
 	  do_right(), do_delete(), breakable(), break_line(),
 	  do_output(), get_buffer(), unget_input(), actual_x(),
-	  strnlenpt(), display_string(), titlebar(), and do_credits().
-	  (David Benbennick and DLR)
+	  strnlenpt(), display_string(), titlebar(), statusbar(),
+	  onekey(), and do_credits(). (David Benbennick and DLR)
 - cut.c:
   do_cut_text()
 	- If keep_cutbuffer is FALSE, only blow away the text in the
diff --git a/src/winio.c b/src/winio.c
index bea1680b..894b2782 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2637,7 +2637,7 @@ void statusbar(const char *msg, ...)
 	    SET(WHITESPACE_DISPLAY);
 #endif
 	free(bar);
-	foo_len = strlen(foo);
+	foo_len = strlenpt(foo);
 	start_x = (COLS - foo_len - 4) / 2;
 
 	wmove(bottomwin, 0, start_x);
@@ -2678,7 +2678,7 @@ void bottombars(const shortcut *s)
     }
 
     /* There will be this many characters per column.  We need at least
-     * 3 to display anything properly.*/
+     * 3 to display anything properly. */
     colwidth = COLS / ((slen / 2) + (slen % 2));
 
     blank_bottombars();
@@ -2726,14 +2726,22 @@ void bottombars(const shortcut *s)
  * the whole string!  We do not bother padding the entry with blanks. */
 void onekey(const char *keystroke, const char *desc, size_t len)
 {
-    assert(keystroke != NULL && desc != NULL && len >= 0);
+    assert(keystroke != NULL && desc != NULL);
+
+    size_t keystroke_len = strlenpt(keystroke) + 1;
+
     wattron(bottomwin, A_REVERSE);
-    waddnstr(bottomwin, keystroke, len);
+    waddnstr(bottomwin, keystroke, actual_x(keystroke, len));
     wattroff(bottomwin, A_REVERSE);
-    len -= strlen(keystroke) + 1;
+
+    if (len > keystroke_len)
+	len -= keystroke_len;
+    else
+	len = 0;
+
     if (len > 0) {
 	waddch(bottomwin, ' ');
-	waddnstr(bottomwin, desc, len);
+	waddnstr(bottomwin, desc, actual_x(desc, len));
     }
 }
 
-- 
GitLab