From 568d2a389cc39de46da6a2ff58dfd44039587170 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Sat, 13 Feb 2016 19:41:12 +0000
Subject: [PATCH] Switching the cursor on and off at the appropriate moments
 (that is: when needed), so that it no longer shows in the help screen nor in
 the file list. This fixes Savannah bug #47126.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5640 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog     |  3 +++
 src/browser.c | 10 ++++------
 src/files.c   |  5 +----
 src/help.c    |  4 +---
 src/nano.c    |  5 +++--
 src/prompt.c  |  3 +++
 src/search.c  |  3 +--
 src/text.c    |  8 +++++++-
 src/winio.c   |  4 ----
 9 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 87faafe6..04e8ce78 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,9 @@
 	fixes Savannah bug #47133.
 	* src/files.c (save_poshistory): Allocate enough space for printing
 	out the line and column numbers.  This fixes Savannah bug #47135.
+	* src/*.c: Switch the cursor on and off at the appropriate moments,
+	so that it no longer shows in the help screen nor in the file list.
+	This fixes Savannah bug #47126.
 
 GNU nano 2.5.2 - 2016.02.12
 
diff --git a/src/browser.c b/src/browser.c
index 39b77150..857bec5d 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -61,6 +61,7 @@ char *do_browser(char *path, DIR *dir)
     functionptrtype func;
 	/* The function of the key the user typed in. */
 
+    /* Don't show a cursor in the file list. */
     curs_set(0);
     blank_statusbar();
     bottombars(MBROWSER);
@@ -115,6 +116,9 @@ char *do_browser(char *path, DIR *dir)
 		/* The path we switch to at the "Go to Directory"
 		 * prompt. */
 
+	/* Make sure that the cursor is off. */
+	curs_set(0);
+
 #ifndef NANO_TINY
 	if (kbinput == KEY_WINCH) {
 	    /* Rebuild the file list and sort it. */
@@ -180,15 +184,12 @@ char *do_browser(char *path, DIR *dir)
 	    do_help_void();
 	    /* The window dimensions might have changed, so act as if. */
 	    kbinput = KEY_WINCH;
-	    curs_set(0);
 #else
 	    say_there_is_no_help();
 #endif
 	} else if (func == do_search) {
 	    /* Search for a filename. */
-	    curs_set(1);
 	    do_filesearch();
-	    curs_set(0);
 	} else if (func == do_research) {
 	    /* Search for another filename. */
 	    do_fileresearch();
@@ -207,7 +208,6 @@ char *do_browser(char *path, DIR *dir)
 	    selected = filelist_len - 1;
 	} else if (func == goto_dir_void) {
 	    /* Go to a specific directory. */
-	    curs_set(1);
 	    i = do_prompt(TRUE,
 #ifndef DISABLE_TABCOMP
 			FALSE,
@@ -219,7 +219,6 @@ char *do_browser(char *path, DIR *dir)
 			/* TRANSLATORS: This is a prompt. */
 			browser_refresh, _("Go To Directory"));
 
-	    curs_set(0);
 	    bottombars(MBROWSER);
 
 	    /* If the directory begins with a newline (i.e. an
@@ -346,7 +345,6 @@ char *do_browser(char *path, DIR *dir)
     }
     titlebar(NULL);
     edit_refresh();
-    curs_set(1);
     if (old_const_update)
 	SET(CONST_UPDATE);
 
diff --git a/src/files.c b/src/files.c
index 400f2a60..0282cb37 100644
--- a/src/files.c
+++ b/src/files.c
@@ -2907,7 +2907,7 @@ char *input_tab(char *buf, bool allow_files, size_t *place, bool
 	    blank_edit();
 	    wmove(edit, 0, 0);
 
-	    /* Disable el cursor. */
+	    /* Don't show a cursor in the list of completions. */
 	    curs_set(0);
 
 	    for (match = 0; match < num_matches; match++) {
@@ -2946,9 +2946,6 @@ char *input_tab(char *buf, bool allow_files, size_t *place, bool
     if (!*list)
 	refresh_func();
 
-    /* Enable el cursor. */
-    curs_set(1);
-
     return buf;
 }
 #endif /* !DISABLE_TABCOMP */
diff --git a/src/help.c b/src/help.c
index 8b3a0d5a..7dd0bfd8 100644
--- a/src/help.c
+++ b/src/help.c
@@ -56,6 +56,7 @@ void do_help(void)
     functionptrtype func;
 	/* The function of the key the user typed in. */
 
+    /* Don't show a cursor in the help screen. */
     curs_set(0);
     blank_edit();
     blank_statusbar();
@@ -123,7 +124,6 @@ void do_help(void)
 #ifndef NANO_TINY
 	if (kbinput == KEY_WINCH) {
 	    kbinput = ERR;
-	    curs_set(0);
 	    continue;    /* Redraw the screen. */
 	}
 #endif
@@ -174,8 +174,6 @@ void do_help(void)
     } else
 	bottombars(oldmenu);
 
-    curs_set(1);
-
 #ifndef DISABLE_BROWSER
     if (oldmenu == MBROWSER || oldmenu == MWHEREISFILE || oldmenu == MGOTODIR)
 	browser_refresh();
diff --git a/src/nano.c b/src/nano.c
index 272b41b8..f9169ed3 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1099,8 +1099,6 @@ int no_help(void)
  * name with the TEMP_FILE flag set, just before the filename prompt. */
 void no_current_file_name_warning(void)
 {
-    curs_set(0);
-
     /* Warn that the current file has no name. */
     statusbar(_("No file name"));
     beep();
@@ -2676,6 +2674,9 @@ int main(int argc, char **argv)
 
 	currmenu = MMAIN;
 
+	/* Turn the cursor on when waiting for input. */
+	curs_set(1);
+
 	/* Read in and interpret characters. */
 	do_input(TRUE);
     }
diff --git a/src/prompt.c b/src/prompt.c
index dcf7ad1e..13d913c7 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -610,6 +610,9 @@ functionptrtype get_prompt_string(int *actual, bool allow_tabs,
      * this case, disable all keys that would change the text if the
      * filename isn't blank and we're at the "Write File" prompt. */
     while (TRUE) {
+	/* Ensure the cursor is on when waiting for input. */
+	curs_set(1);
+
 	kbinput = do_statusbar_input(&ran_func, &finished, refresh_func);
 	assert(statusbar_x <= strlen(answer));
 
diff --git a/src/search.c b/src/search.c
index 45164b26..9d63f7b4 100644
--- a/src/search.c
+++ b/src/search.c
@@ -710,6 +710,7 @@ ssize_t do_replace_loop(
 
 	    edit_refresh();
 
+	    /* Don't show cursor, to not distract from highlighted match. */
 	    curs_set(0);
 
 	    do_replace_highlight(TRUE, exp_word);
@@ -721,8 +722,6 @@ ssize_t do_replace_loop(
 
 	    free(exp_word);
 
-	    curs_set(1);
-
 	    if (i == -1) {	/* We canceled the replace. */
 		if (canceled != NULL)
 		    *canceled = TRUE;
diff --git a/src/text.c b/src/text.c
index 708e1c1c..da105ea1 100644
--- a/src/text.c
+++ b/src/text.c
@@ -3130,8 +3130,11 @@ void do_linter(void)
 			char *msg = charalloc(1024 + strlen(curlint->filename));
 			int i;
 
-			sprintf(msg, _("This message is for unopened file %s, open it in a new buffer?"),
+			sprintf(msg, _("This message is for unopened file %s,"
+					" open it in a new buffer?"),
 				curlint->filename);
+			/* Show a cursor after the question. */
+			curs_set(1);
 			i = do_yesno_prompt(FALSE, msg);
 			free(msg);
 			if (i == -1) {
@@ -3163,6 +3166,9 @@ void do_linter(void)
 	    bottombars(MLINTER);
 	}
 
+	/* Show the cursor to indicate the affected line. */
+	curs_set(1);
+
 	kbinput = get_kbinput(bottomwin);
 
 #ifndef NANO_TINY
diff --git a/src/winio.c b/src/winio.c
index e53054f6..a32453b3 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -311,9 +311,6 @@ int get_kbinput(WINDOW *win)
 {
     int kbinput;
 
-    /* Turn the cursor on when waiting for input. */
-    curs_set(1);
-
     /* Read in a character and interpret it.  Continue doing this until
      * we get a recognized value or sequence. */
     while ((kbinput = parse_kbinput(win)) == ERR)
@@ -3354,7 +3351,6 @@ void do_credits(void)
 	UNSET(NO_HELP);
     window_init();
 
-    curs_set(1);
     nodelay(edit, FALSE);
 
     total_refresh();
-- 
GitLab