display: rework the switching on and off of the cursor

The basic idea is that the cursor is always off, except when it needs
to be on: when waiting for text input, and in a few other cases: when
something was searched and found in the help viewer, and in the file
browser when option -g is in effect.

This fixes https://savannah.gnu.org/bugs/?51923.
Reported-by: Mike Frysinger <vapier@gentoo.org>
master
Benno Schulenberg 2017-09-18 20:34:57 +02:00
parent f6b396f206
commit ae34825f58
9 changed files with 25 additions and 24 deletions

View File

@ -55,8 +55,8 @@ char *do_browser(char *path)
DIR *dir; DIR *dir;
/* The directory whose contents we are showing. */ /* The directory whose contents we are showing. */
/* Don't show a cursor in the file list. */ /* Show a cursor in the file list only when requested. */
curs_set(0); reveal_cursor = ISSET(SHOW_CURSOR);
read_directory_contents: read_directory_contents:
/* We come here when we refresh or select a new directory. */ /* We come here when we refresh or select a new directory. */
@ -106,8 +106,6 @@ char *do_browser(char *path)
titlebar(path); titlebar(path);
while (TRUE) { while (TRUE) {
/* Make sure that the cursor is off. */
curs_set(0);
lastmessage = HUSH; lastmessage = HUSH;
bottombars(MBROWSER); bottombars(MBROWSER);

View File

@ -56,6 +56,8 @@ bool have_palette = FALSE;
/* Whether the colors for the current syntax have been initialized. */ /* Whether the colors for the current syntax have been initialized. */
#endif #endif
bool reveal_cursor = FALSE;
/* Whether the cursor should be shown when waiting for input. */
bool suppress_cursorpos = FALSE; bool suppress_cursorpos = FALSE;
/* Should we skip constant position display for current keystroke? */ /* Should we skip constant position display for current keystroke? */

View File

@ -161,6 +161,7 @@ void do_help(void)
bottombars(MHELP); bottombars(MHELP);
wnoutrefresh(bottomwin); wnoutrefresh(bottomwin);
reveal_cursor = FALSE;
/* Extract the title from the head of the help text. */ /* Extract the title from the head of the help text. */
length = break_line(help_text, MAX_BUF_SIZE, TRUE); length = break_line(help_text, MAX_BUF_SIZE, TRUE);
@ -224,12 +225,13 @@ void do_help(void)
} else if (func == do_exit) { } else if (func == do_exit) {
/* Exit from the help viewer. */ /* Exit from the help viewer. */
close_buffer(); close_buffer();
curs_set(0);
break; break;
} else } else
unbound_key(kbinput); unbound_key(kbinput);
/* If we searched and found something, let the cursor show it. */ /* If we searched and found something, let the cursor show it. */
curs_set(didfind == 1 ? 1 : 0); reveal_cursor = (didfind == 1);
currmenu = MHELP; currmenu = MHELP;
edit_refresh(); edit_refresh();

View File

@ -1579,9 +1579,13 @@ int do_input(bool allow_funcs)
const sc *s; const sc *s;
bool have_shortcut; bool have_shortcut;
reveal_cursor = TRUE;
/* Read in a keystroke. */ /* Read in a keystroke. */
input = get_kbinput(edit); input = get_kbinput(edit);
reveal_cursor = FALSE;
#ifndef NANO_TINY #ifndef NANO_TINY
if (input == KEY_WINCH) if (input == KEY_WINCH)
return KEY_WINCH; return KEY_WINCH;
@ -2650,9 +2654,6 @@ int main(int argc, char **argv)
} else } else
edit_refresh(); edit_refresh();
/* Make sure the cursor is visible. */
curs_set(1);
focusing = TRUE; focusing = TRUE;
/* Forget any earlier statusbar x position. */ /* Forget any earlier statusbar x position. */

View File

@ -478,7 +478,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
while (TRUE) { while (TRUE) {
/* Ensure the cursor is shown when waiting for input. */ /* Ensure the cursor is shown when waiting for input. */
curs_set(1); reveal_cursor = TRUE;
kbinput = do_statusbar_input(&ran_func, &finished); kbinput = do_statusbar_input(&ran_func, &finished);
@ -597,6 +597,8 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
} }
#endif #endif
reveal_cursor = FALSE;
*actual = kbinput; *actual = kbinput;
return func; return func;
@ -746,8 +748,7 @@ int do_yesno_prompt(bool all, const char *msg)
wnoutrefresh(bottomwin); wnoutrefresh(bottomwin);
/* When not replacing, show the cursor. */ /* When not replacing, show the cursor. */
if (!all) reveal_cursor = !all;
curs_set(1);
currmenu = MYESNO; currmenu = MYESNO;
kbinput = get_kbinput(bottomwin); kbinput = get_kbinput(bottomwin);

View File

@ -47,6 +47,7 @@ extern int editwincols;
extern bool have_palette; extern bool have_palette;
#endif #endif
extern bool reveal_cursor;
extern bool suppress_cursorpos; extern bool suppress_cursorpos;
extern message_type lastmessage; extern message_type lastmessage;

View File

@ -608,9 +608,6 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
/* Refresh the edit window, scrolling it if necessary. */ /* Refresh the edit window, scrolling it if necessary. */
edit_refresh(); edit_refresh();
/* Don't show cursor, to not distract from highlighted match. */
curs_set(0);
spotlight(TRUE, from_col, to_col); spotlight(TRUE, from_col, to_col);
/* TRANSLATORS: This is a prompt. */ /* TRANSLATORS: This is a prompt. */

View File

@ -2478,7 +2478,6 @@ void do_justify(bool full_justify)
#endif #endif
statusbar(_("Can now UnJustify!")); statusbar(_("Can now UnJustify!"));
place_the_cursor(); place_the_cursor();
curs_set(1);
kbinput = do_input(FALSE); kbinput = do_input(FALSE);
#ifndef NANO_TINY #ifndef NANO_TINY
} while (kbinput == KEY_WINCH); } while (kbinput == KEY_WINCH);
@ -3337,8 +3336,8 @@ void do_linter(void)
/* Place and show the cursor to indicate the affected line. */ /* Place and show the cursor to indicate the affected line. */
place_the_cursor(); place_the_cursor();
reveal_cursor = TRUE;
wnoutrefresh(edit); wnoutrefresh(edit);
curs_set(1);
kbinput = get_kbinput(bottomwin); kbinput = get_kbinput(bottomwin);
@ -3585,7 +3584,7 @@ void do_verbatim_input(void)
* inserted verbatim. */ * inserted verbatim. */
statusbar(_("Verbatim Input")); statusbar(_("Verbatim Input"));
place_the_cursor(); place_the_cursor();
curs_set(1); reveal_cursor = TRUE;
/* Read in all the verbatim characters. */ /* Read in all the verbatim characters. */
kbinput = get_verbatim_kbinput(edit, &kbinput_len); kbinput = get_verbatim_kbinput(edit, &kbinput_len);

View File

@ -120,9 +120,14 @@ void get_key_buffer(WINDOW *win)
* screen updates. */ * screen updates. */
doupdate(); doupdate();
if (reveal_cursor)
curs_set(1);
/* Read in the first character using whatever mode we're in. */ /* Read in the first character using whatever mode we're in. */
input = wgetch(win); input = wgetch(win);
curs_set(0);
#ifndef NANO_TINY #ifndef NANO_TINY
if (the_window_resized) { if (the_window_resized) {
ungetch(input); ungetch(input);
@ -1553,6 +1558,8 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
char *multibyte; char *multibyte;
int onebyte, i; int onebyte, i;
reveal_cursor = FALSE;
while (unicode == ERR) { while (unicode == ERR) {
free(kbinput); free(kbinput);
while ((kbinput = get_input(win, 1)) == NULL) while ((kbinput = get_input(win, 1)) == NULL)
@ -2186,9 +2193,6 @@ void statusline(message_type importance, const char *msg, ...)
lastmessage = importance; lastmessage = importance;
/* Turn the cursor off while fiddling in the statusbar. */
curs_set(0);
blank_statusbar(); blank_statusbar();
/* Construct the message out of all the arguments. */ /* Construct the message out of all the arguments. */
@ -3369,9 +3373,6 @@ void do_cursorpos(bool force)
return; return;
} }
/* Hide the cursor while we are calculating. */
curs_set(0);
/* Determine the size of the file up to the cursor. */ /* Determine the size of the file up to the cursor. */
saved_byte = openfile->current->data[openfile->current_x]; saved_byte = openfile->current->data[openfile->current_x];
openfile->current->data[openfile->current_x] = '\0'; openfile->current->data[openfile->current_x] = '\0';
@ -3607,7 +3608,6 @@ void do_credits(void)
window_init(); window_init();
} }
curs_set(0);
nodelay(edit, TRUE); nodelay(edit, TRUE);
blank_titlebar(); blank_titlebar();