commit c74d2632bb9d1e676b2ec99fe45df7ce16b15e4a
parent ae34825f58d2f7d7a6e3bcf97868277a5c12e6c8
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Wed, 20 Sep 2017 22:20:18 +0200
tweaks: make the switching on and off of the cursor a bit more compact
Diffstat:
9 files changed, 26 insertions(+), 38 deletions(-)
diff --git a/src/browser.c b/src/browser.c
@@ -55,9 +55,6 @@ char *do_browser(char *path)
DIR *dir;
/* The directory whose contents we are showing. */
- /* 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. */
@@ -117,7 +114,7 @@ char *do_browser(char *path)
old_selected = selected;
- kbinput = get_kbinput(edit);
+ kbinput = get_kbinput(edit, ISSET(SHOW_CURSOR));
#ifdef ENABLE_MOUSE
if (kbinput == KEY_MOUSE) {
diff --git a/src/global.c b/src/global.c
@@ -56,8 +56,6 @@ 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
@@ -158,10 +158,10 @@ void do_help(void)
help_init();
inhelp = TRUE;
location = 0;
+ didfind = 0;
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);
@@ -182,9 +182,10 @@ void do_help(void)
while (TRUE) {
lastmessage = HUSH;
focusing = TRUE;
- didfind = 0;
- kbinput = get_kbinput(edit);
+ /* Show the cursor when we searched and found something. */
+ kbinput = get_kbinput(edit, didfind == 1);
+ didfind = 0;
func = parse_help_input(&kbinput);
@@ -230,9 +231,6 @@ void do_help(void)
} else
unbound_key(kbinput);
- /* If we searched and found something, let the cursor show it. */
- reveal_cursor = (didfind == 1);
-
currmenu = MHELP;
edit_refresh();
diff --git a/src/nano.c b/src/nano.c
@@ -1579,12 +1579,8 @@ 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;
+ /* Read in a keystroke, and show the cursor while waiting. */
+ input = get_kbinput(edit, VISIBLE);
#ifndef NANO_TINY
if (input == KEY_WINCH)
@@ -1597,7 +1593,7 @@ int do_input(bool allow_funcs)
if (do_mouse() == 1)
/* The click was on a shortcut -- read in the character
* that it was converted into. */
- input = get_kbinput(edit);
+ input = get_kbinput(edit, BLIND);
else
/* The click was invalid or has been handled -- get out. */
return ERR;
diff --git a/src/nano.h b/src/nano.h
@@ -135,6 +135,9 @@
#define BACKWARD FALSE
#define FORWARD TRUE
+#define BLIND FALSE
+#define VISIBLE TRUE
+
/* Enumeration types. */
typedef enum {
NIX_FILE, DOS_FILE, MAC_FILE
diff --git a/src/prompt.c b/src/prompt.c
@@ -48,7 +48,7 @@ int do_statusbar_input(bool *ran_func, bool *finished)
*finished = FALSE;
/* Read in a character. */
- input = get_kbinput(bottomwin);
+ input = get_kbinput(bottomwin, VISIBLE);
#ifndef NANO_TINY
if (input == KEY_WINCH)
@@ -60,7 +60,7 @@ int do_statusbar_input(bool *ran_func, bool *finished)
* shortcut character. */
if (input == KEY_MOUSE) {
if (do_statusbar_mouse() == 1)
- input = get_kbinput(bottomwin);
+ input = get_kbinput(bottomwin, BLIND);
else
return ERR;
}
@@ -477,9 +477,6 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
update_the_statusbar();
while (TRUE) {
- /* Ensure the cursor is shown when waiting for input. */
- reveal_cursor = TRUE;
-
kbinput = do_statusbar_input(&ran_func, &finished);
#ifndef NANO_TINY
@@ -597,8 +594,6 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
}
#endif
- reveal_cursor = FALSE;
-
*actual = kbinput;
return func;
@@ -746,12 +741,10 @@ int do_yesno_prompt(bool all, const char *msg)
wattroff(bottomwin, interface_color_pair[TITLE_BAR]);
wnoutrefresh(bottomwin);
-
- /* When not replacing, show the cursor. */
- reveal_cursor = !all;
-
currmenu = MYESNO;
- kbinput = get_kbinput(bottomwin);
+
+ /* When not replacing, show the cursor while waiting for a key. */
+ kbinput = get_kbinput(bottomwin, !all);
func = func_from_key(&kbinput);
diff --git a/src/proto.h b/src/proto.h
@@ -47,7 +47,6 @@ extern int editwincols;
extern bool have_palette;
#endif
-extern bool reveal_cursor;
extern bool suppress_cursorpos;
extern message_type lastmessage;
@@ -631,7 +630,7 @@ void dump_filestruct_reverse(void);
void get_key_buffer(WINDOW *win);
size_t get_key_buffer_len(void);
void unget_kbinput(int kbinput, bool metakey);
-int get_kbinput(WINDOW *win);
+int get_kbinput(WINDOW *win, bool showcursor);
int parse_kbinput(WINDOW *win);
int arrow_from_abcd(int kbinput);
int parse_escape_sequence(WINDOW *win, int kbinput);
diff --git a/src/text.c b/src/text.c
@@ -3334,12 +3334,11 @@ void do_linter(void)
bottombars(MLINTER);
}
- /* Place and show the cursor to indicate the affected line. */
+ /* Place the cursor to indicate the affected line. */
place_the_cursor();
- reveal_cursor = TRUE;
wnoutrefresh(edit);
- kbinput = get_kbinput(bottomwin);
+ kbinput = get_kbinput(bottomwin, VISIBLE);
#ifndef NANO_TINY
if (kbinput == KEY_WINCH)
@@ -3584,7 +3583,6 @@ void do_verbatim_input(void)
* inserted verbatim. */
statusbar(_("Verbatim Input"));
place_the_cursor();
- 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
@@ -49,6 +49,8 @@ static int statusblank = 0;
static bool seen_wide = FALSE;
/* Whether we've seen a multicolumn character in the current line. */
#endif
+static bool reveal_cursor = FALSE;
+ /* Whether the cursor should be shown when waiting for input. */
/* Control character compatibility:
*
@@ -290,10 +292,12 @@ int *get_input(WINDOW *win, size_t input_len)
}
/* Read in a single keystroke, ignoring any that are invalid. */
-int get_kbinput(WINDOW *win)
+int get_kbinput(WINDOW *win, bool showcursor)
{
int kbinput = ERR;
+ reveal_cursor = showcursor;
+
/* Extract one keystroke from the input stream. */
while (kbinput == ERR)
kbinput = parse_kbinput(win);
@@ -1529,6 +1533,8 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
{
int *kbinput;
+ reveal_cursor = TRUE;
+
/* Read in the first code. */
while ((kbinput = get_input(win, 1)) == NULL)
;