diff --git a/src/browser.c b/src/browser.c index de264cdd30cf3cd53be018108b67ac3044cc8ee2..ff1b4033ff53ff457be142dbb98020d727678ed1 100644 --- a/src/browser.c +++ b/src/browser.c @@ -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); diff --git a/src/global.c b/src/global.c index 46633e3826cf17c83828a4823668e8f5d2656579..f1cc853025e5b88a1a47474145e2c03f88a40136 100644 --- a/src/global.c +++ b/src/global.c @@ -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? */ diff --git a/src/help.c b/src/help.c index 84e957db10082f26c01c6f76e45d7e2b45b8c7dd..69aa2e98468902a737180581809da131d986b7d2 100644 --- a/src/help.c +++ b/src/help.c @@ -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(); diff --git a/src/nano.c b/src/nano.c index a5ba3e622ca2a70f989d38f19c5f74580003fa19..25e22b32dcc3bdf743163d8f343b74fd748b8bf3 100644 --- a/src/nano.c +++ b/src/nano.c @@ -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. */ diff --git a/src/prompt.c b/src/prompt.c index 5785cb4cf43721d3c209c8dd5d8a7077b1fb9bed..f61d9a945c908aa99fc5e026d68a17f55dac3990 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -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); diff --git a/src/proto.h b/src/proto.h index bd3a3cb08903b6960fb019e40793a81410be1772..c6303f345bfe15204de6ebeb0e29ea55c2c815bf 100644 --- a/src/proto.h +++ b/src/proto.h @@ -47,6 +47,7 @@ extern int editwincols; extern bool have_palette; #endif +extern bool reveal_cursor; extern bool suppress_cursorpos; extern message_type lastmessage; diff --git a/src/search.c b/src/search.c index f8049193eb451c70e3964659d364d9437f2af5c5..ea7b6b6578dfc41c45b93a726bea56b000e2e8d6 100644 --- a/src/search.c +++ b/src/search.c @@ -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. */ diff --git a/src/text.c b/src/text.c index b302163cab36ed7470592f7d5a8225b27785f13a..522197e5ecdb5fd6e34c651fff3db54d1a24da43 100644 --- a/src/text.c +++ b/src/text.c @@ -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); diff --git a/src/winio.c b/src/winio.c index b2e5bab92301fd89b8d0c36c118ab42235a92df7..7225fd3deb5e7ad964437f23697ded4940434b03 100644 --- a/src/winio.c +++ b/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();