From 297851a647f1c94cb4cf4e81d4ad69b1da82a1b2 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Fri, 25 Mar 2005 05:00:32 +0000
Subject: [PATCH] in titlebar(), make sure that the (mv)?waddnstr() calls take
 the proper number of bytes when using multibyte characters, so that multibyte
 strings aren't prematurely cut off; also allow the "View" state to be
 displayed when a filename is passed in, in case we're in multibuffer mode and
 inside the file browser

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

diff --git a/ChangeLog b/ChangeLog
index a7194f10..728f005f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -40,6 +40,14 @@ CVS code -
   regexec_safe()
 	- Rename to safe_regexec() for consistency. (DLR)
 - winio.c:
+  titlebar()
+	- Make sure that the (mv)?waddnstr() calls take the proper
+	  number of bytes when using multibyte characters, so that
+	  multibyte strings aren't prematurely cut off. (DLR, found by
+	  Jordi)
+	- Allow the "View" state to be displayed when a filename is
+	  passed in, in case we're in multibuffer mode and inside the
+	  file browser. (DLR)
   help_line_len()
 	- Make the text display more flexible, and closer to what nano
 	  1.2.x does. (DLR)
diff --git a/src/winio.c b/src/winio.c
index 69dcaa00..f4a47dd7 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2730,7 +2730,6 @@ void titlebar(const char *path)
     assert(COLS >= 0);
 
     wattron(topwin, A_REVERSE);
-
     blank_titlebar();
 
     if (COLS <= 5 || COLS - 5 < verlen)
@@ -2752,7 +2751,7 @@ void titlebar(const char *path)
 
     if (ISSET(MODIFIED))
 	state = _("Modified");
-    else if (path == NULL && ISSET(VIEW_MODE))
+    else if (ISSET(VIEW_MODE))
 	state = _("View");
     else {
 	if (space > 0)
@@ -2760,6 +2759,7 @@ void titlebar(const char *path)
 	state = &hblank[COLS - statelen];
     }
     statelen = strnlenpt(state, COLS);
+
     /* We need a space before state. */
     if ((ISSET(MODIFIED) || ISSET(VIEW_MODE)) && statelen < COLS)
 	statelen++;
@@ -2783,6 +2783,7 @@ void titlebar(const char *path)
     assert(statelen < space);
 
     prefixlen = strnlenpt(prefix, space - statelen);
+
     /* If newfie is FALSE, we need a space after prefix. */
     if (!newfie && prefixlen + statelen < space)
 	prefixlen++;
@@ -2794,6 +2795,7 @@ void titlebar(const char *path)
     else
 	space = 0;
 	/* space is now the room we have for the file name. */
+
     if (!newfie) {
 	size_t lenpt = strlenpt(path), start_col;
 
@@ -2814,7 +2816,7 @@ void titlebar(const char *path)
 
 	/* There is room for the whole filename, so we center it. */
 	waddnstr(topwin, hblank, (space - exppathlen) / 3);
-	waddnstr(topwin, prefix, prefixlen);
+	waddnstr(topwin, prefix, actual_x(prefix, prefixlen));
 	if (!newfie) {
 	    assert(strlenpt(prefix) + 1 == prefixlen);
 
@@ -2823,7 +2825,7 @@ void titlebar(const char *path)
 	}
     } else {
 	/* We will say something like "File: ...ename". */
-	waddnstr(topwin, prefix, prefixlen);
+	waddnstr(topwin, prefix, actual_x(prefix, prefixlen));
 	if (space <= -3 || newfie)
 	    goto the_end;
 	waddch(topwin, ' ');
@@ -2837,12 +2839,13 @@ void titlebar(const char *path)
     free(exppath);
 
     if (COLS <= 1 || statelen >= COLS - 1)
-	mvwaddnstr(topwin, 0, 0, state, COLS);
+	mvwaddnstr(topwin, 0, 0, state, actual_x(state, COLS));
     else {
 	assert(COLS - statelen - 2 >= 0);
 
 	mvwaddch(topwin, 0, COLS - statelen - 2, ' ');
-	mvwaddnstr(topwin, 0, COLS - statelen - 1, state, statelen);
+	mvwaddnstr(topwin, 0, COLS - statelen - 1, state,
+		actual_x(state, statelen));
     }
 
     wattroff(topwin, A_REVERSE);
-- 
GitLab