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
parent
f6b396f206
commit
ae34825f58
|
@ -55,8 +55,8 @@ char *do_browser(char *path)
|
|||
DIR *dir;
|
||||
/* The directory whose contents we are showing. */
|
||||
|
||||
/* Don't show a cursor in the file list. */
|
||||
curs_set(0);
|
||||
/* Show a cursor in the file list only when requested. */
|
||||
reveal_cursor = ISSET(SHOW_CURSOR);
|
||||
|
||||
read_directory_contents:
|
||||
/* We come here when we refresh or select a new directory. */
|
||||
|
@ -106,8 +106,6 @@ char *do_browser(char *path)
|
|||
titlebar(path);
|
||||
|
||||
while (TRUE) {
|
||||
/* Make sure that the cursor is off. */
|
||||
curs_set(0);
|
||||
lastmessage = HUSH;
|
||||
|
||||
bottombars(MBROWSER);
|
||||
|
|
|
@ -56,6 +56,8 @@ bool have_palette = FALSE;
|
|||
/* Whether the colors for the current syntax have been initialized. */
|
||||
#endif
|
||||
|
||||
bool reveal_cursor = FALSE;
|
||||
/* Whether the cursor should be shown when waiting for input. */
|
||||
bool suppress_cursorpos = FALSE;
|
||||
/* Should we skip constant position display for current keystroke? */
|
||||
|
||||
|
|
|
@ -161,6 +161,7 @@ void do_help(void)
|
|||
|
||||
bottombars(MHELP);
|
||||
wnoutrefresh(bottomwin);
|
||||
reveal_cursor = FALSE;
|
||||
|
||||
/* Extract the title from the head of the help text. */
|
||||
length = break_line(help_text, MAX_BUF_SIZE, TRUE);
|
||||
|
@ -224,12 +225,13 @@ void do_help(void)
|
|||
} else if (func == do_exit) {
|
||||
/* Exit from the help viewer. */
|
||||
close_buffer();
|
||||
curs_set(0);
|
||||
break;
|
||||
} else
|
||||
unbound_key(kbinput);
|
||||
|
||||
/* If we searched and found something, let the cursor show it. */
|
||||
curs_set(didfind == 1 ? 1 : 0);
|
||||
reveal_cursor = (didfind == 1);
|
||||
|
||||
currmenu = MHELP;
|
||||
edit_refresh();
|
||||
|
|
|
@ -1579,9 +1579,13 @@ int do_input(bool allow_funcs)
|
|||
const sc *s;
|
||||
bool have_shortcut;
|
||||
|
||||
reveal_cursor = TRUE;
|
||||
|
||||
/* Read in a keystroke. */
|
||||
input = get_kbinput(edit);
|
||||
|
||||
reveal_cursor = FALSE;
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (input == KEY_WINCH)
|
||||
return KEY_WINCH;
|
||||
|
@ -2650,9 +2654,6 @@ int main(int argc, char **argv)
|
|||
} else
|
||||
edit_refresh();
|
||||
|
||||
/* Make sure the cursor is visible. */
|
||||
curs_set(1);
|
||||
|
||||
focusing = TRUE;
|
||||
|
||||
/* Forget any earlier statusbar x position. */
|
||||
|
|
|
@ -478,7 +478,7 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
|
|||
|
||||
while (TRUE) {
|
||||
/* Ensure the cursor is shown when waiting for input. */
|
||||
curs_set(1);
|
||||
reveal_cursor = TRUE;
|
||||
|
||||
kbinput = do_statusbar_input(&ran_func, &finished);
|
||||
|
||||
|
@ -597,6 +597,8 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
|
|||
}
|
||||
#endif
|
||||
|
||||
reveal_cursor = FALSE;
|
||||
|
||||
*actual = kbinput;
|
||||
|
||||
return func;
|
||||
|
@ -746,8 +748,7 @@ int do_yesno_prompt(bool all, const char *msg)
|
|||
wnoutrefresh(bottomwin);
|
||||
|
||||
/* When not replacing, show the cursor. */
|
||||
if (!all)
|
||||
curs_set(1);
|
||||
reveal_cursor = !all;
|
||||
|
||||
currmenu = MYESNO;
|
||||
kbinput = get_kbinput(bottomwin);
|
||||
|
|
|
@ -47,6 +47,7 @@ extern int editwincols;
|
|||
extern bool have_palette;
|
||||
#endif
|
||||
|
||||
extern bool reveal_cursor;
|
||||
extern bool suppress_cursorpos;
|
||||
|
||||
extern message_type lastmessage;
|
||||
|
|
|
@ -608,9 +608,6 @@ ssize_t do_replace_loop(const char *needle, bool whole_word_only,
|
|||
/* Refresh the edit window, scrolling it if necessary. */
|
||||
edit_refresh();
|
||||
|
||||
/* Don't show cursor, to not distract from highlighted match. */
|
||||
curs_set(0);
|
||||
|
||||
spotlight(TRUE, from_col, to_col);
|
||||
|
||||
/* TRANSLATORS: This is a prompt. */
|
||||
|
|
|
@ -2478,7 +2478,6 @@ void do_justify(bool full_justify)
|
|||
#endif
|
||||
statusbar(_("Can now UnJustify!"));
|
||||
place_the_cursor();
|
||||
curs_set(1);
|
||||
kbinput = do_input(FALSE);
|
||||
#ifndef NANO_TINY
|
||||
} while (kbinput == KEY_WINCH);
|
||||
|
@ -3337,8 +3336,8 @@ void do_linter(void)
|
|||
|
||||
/* Place and show the cursor to indicate the affected line. */
|
||||
place_the_cursor();
|
||||
reveal_cursor = TRUE;
|
||||
wnoutrefresh(edit);
|
||||
curs_set(1);
|
||||
|
||||
kbinput = get_kbinput(bottomwin);
|
||||
|
||||
|
@ -3585,7 +3584,7 @@ void do_verbatim_input(void)
|
|||
* inserted verbatim. */
|
||||
statusbar(_("Verbatim Input"));
|
||||
place_the_cursor();
|
||||
curs_set(1);
|
||||
reveal_cursor = TRUE;
|
||||
|
||||
/* Read in all the verbatim characters. */
|
||||
kbinput = get_verbatim_kbinput(edit, &kbinput_len);
|
||||
|
|
14
src/winio.c
14
src/winio.c
|
@ -120,9 +120,14 @@ void get_key_buffer(WINDOW *win)
|
|||
* screen updates. */
|
||||
doupdate();
|
||||
|
||||
if (reveal_cursor)
|
||||
curs_set(1);
|
||||
|
||||
/* Read in the first character using whatever mode we're in. */
|
||||
input = wgetch(win);
|
||||
|
||||
curs_set(0);
|
||||
|
||||
#ifndef NANO_TINY
|
||||
if (the_window_resized) {
|
||||
ungetch(input);
|
||||
|
@ -1553,6 +1558,8 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
|
|||
char *multibyte;
|
||||
int onebyte, i;
|
||||
|
||||
reveal_cursor = FALSE;
|
||||
|
||||
while (unicode == ERR) {
|
||||
free(kbinput);
|
||||
while ((kbinput = get_input(win, 1)) == NULL)
|
||||
|
@ -2186,9 +2193,6 @@ void statusline(message_type importance, const char *msg, ...)
|
|||
|
||||
lastmessage = importance;
|
||||
|
||||
/* Turn the cursor off while fiddling in the statusbar. */
|
||||
curs_set(0);
|
||||
|
||||
blank_statusbar();
|
||||
|
||||
/* Construct the message out of all the arguments. */
|
||||
|
@ -3369,9 +3373,6 @@ void do_cursorpos(bool force)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Hide the cursor while we are calculating. */
|
||||
curs_set(0);
|
||||
|
||||
/* Determine the size of the file up to the cursor. */
|
||||
saved_byte = openfile->current->data[openfile->current_x];
|
||||
openfile->current->data[openfile->current_x] = '\0';
|
||||
|
@ -3607,7 +3608,6 @@ void do_credits(void)
|
|||
window_init();
|
||||
}
|
||||
|
||||
curs_set(0);
|
||||
nodelay(edit, TRUE);
|
||||
|
||||
blank_titlebar();
|
||||
|
|
Loading…
Reference in New Issue