From d55e97bec8f1507829f5bf04b47b5bed9a924917 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Wed, 27 Feb 2019 14:37:53 -0600
Subject: [PATCH 2/2] display: indicate being at a prompt with a
 display_string() parameter

This fixes http://savannah.gnu.org/bugs/?55773.
---
 src/browser.c |  4 ++--
 src/files.c   |  8 ++++----
 src/prompt.c  |  2 +-
 src/proto.h   |  3 ++-
 src/search.c  |  4 ++--
 src/winio.c   | 23 +++++++++++++----------
 6 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/src/browser.c b/src/browser.c
index a192b56c..e66418ef 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -529,7 +529,7 @@ void browser_refresh(void)
 				/* Whether to put an ellipsis before the filename?  We don't
 				 * waste space on dots when there are fewer than 15 columns. */
 		char *disp = display_string(thename, dots ?
-				namelen + infomaxlen + 4 - longest : 0, longest, FALSE);
+				namelen + infomaxlen + 4 - longest : 0, longest, FALSE, FALSE);
 				/* The filename (or a fragment of it) in displayable format.
 				 * When a fragment, account for dots plus one space padding. */
 
@@ -667,7 +667,7 @@ int filesearch_init(bool forwards)
 
 	/* If something was searched for before, show it between square brackets. */
 	if (*last_search != '\0') {
-		char *disp = display_string(last_search, 0, COLS / 3, FALSE);
+		char *disp = display_string(last_search, 0, COLS / 3, FALSE, FALSE);
 
 		thedefault = charalloc(strlen(disp) + 7);
 		/* We use (COLS / 3) here because we need to see more on the line. */
diff --git a/src/files.c b/src/files.c
index be2045f9..e065f508 100644
--- a/src/files.c
+++ b/src/files.c
@@ -359,13 +359,13 @@ int do_lockfile(const char *filename)
 			postedname = mallocstrcpy(NULL, "_");
 		else if (room < strlenpt(filename)) {
 			char *fragment = display_string(filename,
-								strlenpt(filename) - room + 3, room, FALSE);
+								strlenpt(filename) - room + 3, room, FALSE, FALSE);
 			postedname = charalloc(strlen(fragment) + 4);
 			strcpy(postedname, "...");
 			strcat(postedname, fragment);
 			free(fragment);
 		} else
-			postedname = display_string(filename, 0, room, FALSE);
+			postedname = display_string(filename, 0, room, FALSE, FALSE);
 
 		/* Allow extra space for username (14), program name (8), PID (8),
 		 * and terminating \0 (1), minus the %s (2) for the file name. */
@@ -2256,7 +2256,7 @@ int do_writeout(bool exiting, bool withprompt)
 				if (name_exists) {
 					char *question = _("File \"%s\" exists; OVERWRITE? ");
 					char *name = display_string(answer, 0,
-										COLS - strlenpt(question) + 1, FALSE);
+										COLS - strlenpt(question) + 1, FALSE, FALSE);
 					char *message = charalloc(strlen(question) +
 												strlen(name) + 1);
 
@@ -2704,7 +2704,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
 					break;
 				}
 
-				disp = display_string(matches[match], 0, longest_name, FALSE);
+				disp = display_string(matches[match], 0, longest_name, FALSE, FALSE);
 				waddstr(edit, disp);
 				free(disp);
 
diff --git a/src/prompt.c b/src/prompt.c
index 5a84813e..e4253363 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -400,7 +400,7 @@ void draw_the_promptbar(void)
 	waddch(bottomwin, ':');
 	waddch(bottomwin, (the_page == 0) ? ' ' : '<');
 
-	expanded = display_string(answer, the_page, COLS - base, FALSE);
+	expanded = display_string(answer, the_page, COLS - base, FALSE, TRUE);
 	waddstr(bottomwin, expanded);
 	free(expanded);
 
diff --git a/src/proto.h b/src/proto.h
index b3a79c5d..4d64a479 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -618,7 +618,8 @@ void blank_statusbar(void);
 void wipe_statusbar(void);
 void blank_bottombars(void);
 void check_statusblank(void);
-char *display_string(const char *buf, size_t column, size_t span, bool isdata);
+char *display_string(const char *buf, size_t column, size_t span, bool isdata,
+						bool isprompt);
 void titlebar(const char *path);
 void statusbar(const char *msg);
 void warn_and_shortly_pause(const char *msg);
diff --git a/src/search.c b/src/search.c
index 98e0204a..5bdd1b02 100644
--- a/src/search.c
+++ b/src/search.c
@@ -83,7 +83,7 @@ void search_init(bool replacing, bool keep_the_answer)
 
 	/* If something was searched for earlier, include it in the prompt. */
 	if (*last_search != '\0') {
-		char *disp = display_string(last_search, 0, COLS / 3, FALSE);
+		char *disp = display_string(last_search, 0, COLS / 3, FALSE, FALSE);
 
 		thedefault = charalloc(strlen(disp) + 7);
 		/* We use (COLS / 3) here because we need to see more on the line. */
@@ -388,7 +388,7 @@ void do_findnext(void)
 /* Report on the status bar that the given string was not found. */
 void not_found_msg(const char *str)
 {
-	char *disp = display_string(str, 0, (COLS / 2) + 1, FALSE);
+	char *disp = display_string(str, 0, (COLS / 2) + 1, FALSE, FALSE);
 	size_t numchars = actual_x(disp, strnlenpt(disp, COLS / 2));
 
 	statusline(HUSH, _("\"%.*s%s\" not found"), numchars, disp,
diff --git a/src/winio.c b/src/winio.c
index 53798e17..f43b60bc 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -1863,8 +1863,11 @@ void check_statusblank(void)
  * at most span columns.  column is zero-based, and span is one-based, so
  * span == 0 means you get "" returned.  The returned string is dynamically
  * allocated, and should be freed.  If isdata is TRUE, the caller might put
- * "<" at the beginning or ">" at the end of the line if it's too long. */
-char *display_string(const char *buf, size_t column, size_t span, bool isdata)
+ * "<" at the beginning or ">" at the end of the line if it's too long.  If
+ * isprompt is TRUE, the caller might put ">" at the end of the line if it's
+ * too long. */
+char *display_string(const char *buf, size_t column, size_t span, bool isdata,
+						bool isprompt)
 {
 	size_t start_index = actual_x(buf, column);
 		/* The index of the first character that the caller wishes to show. */
@@ -1989,7 +1992,7 @@ char *display_string(const char *buf, size_t column, size_t span, bool isdata)
 
 	/* If there is more text than can be shown, make room for the ">". */
 	if ((*buf != '\0' || column > beyond) &&
-					(currmenu != MMAIN || (isdata && !ISSET(SOFTWRAP)))) {
+					(isprompt || (isdata && !ISSET(SOFTWRAP)))) {
 		do {
 			index = move_mbleft(converted, index);
 		} while (mbwidth(converted + index) == 0);
@@ -2143,13 +2146,13 @@ void titlebar(const char *path)
 
 	/* Print the full path if there's room; otherwise, dottify it. */
 	if (pathlen + pluglen + statelen <= COLS) {
-		caption = display_string(path, 0, pathlen, FALSE);
+		caption = display_string(path, 0, pathlen, FALSE, FALSE);
 		waddstr(topwin, caption);
 		free(caption);
 	} else if (5 + statelen <= COLS) {
 		waddstr(topwin, "...");
 		caption = display_string(path, 3 + pathlen - COLS + statelen,
-										COLS - statelen, FALSE);
+										COLS - statelen, FALSE, FALSE);
 		waddstr(topwin, caption);
 		free(caption);
 	}
@@ -2240,7 +2243,7 @@ void statusline(message_type importance, const char *msg, ...)
 	compound = charalloc(MAXCHARLEN * (COLS + 1));
 	vsnprintf(compound, MAXCHARLEN * (COLS + 1), msg, ap);
 	va_end(ap);
-	message = display_string(compound, 0, COLS, FALSE);
+	message = display_string(compound, 0, COLS, FALSE, FALSE);
 	free(compound);
 
 	start_col = (COLS - strlenpt(message)) / 2;
@@ -2772,7 +2775,7 @@ int update_line(filestruct *fileptr, size_t index)
 
 	/* Expand the line, replacing tabs with spaces, and control
 	 * characters with their displayed forms. */
-	converted = display_string(fileptr->data, from_col, editwincols, TRUE);
+	converted = display_string(fileptr->data, from_col, editwincols, TRUE, FALSE);
 
 	/* Draw the line. */
 	edit_draw(fileptr, converted, row, from_col);
@@ -2842,7 +2845,7 @@ int update_softwrapped_line(filestruct *fileptr)
 		blank_row(edit, row, 0, COLS);
 
 		/* Convert the chunk to its displayable form and draw it. */
-		converted = display_string(fileptr->data, from_col, to_col - from_col, TRUE);
+		converted = display_string(fileptr->data, from_col, to_col - from_col, TRUE, FALSE);
 		edit_draw(fileptr, converted, row++, from_col);
 		free(converted);
 
@@ -3443,7 +3446,7 @@ void spotlight(size_t from_col, size_t to_col)
 		to_col++;
 	} else
 		word = display_string(openfile->current->data, from_col,
-								to_col - from_col, FALSE);
+								to_col - from_col, FALSE, FALSE);
 
 	word_span = strlenpt(word);
 
@@ -3496,7 +3499,7 @@ void spotlight_softwrapped(size_t from_col, size_t to_col)
 			break_col++;
 		} else
 			word = display_string(openfile->current->data, from_col,
-										break_col - from_col, FALSE);
+										break_col - from_col, FALSE, FALSE);
 
 		wattron(edit, interface_color_pair[SELECTED_TEXT]);
 
-- 
2.21.0

