tweaks: make the switching on and off of the cursor a bit more compact

master
Benno Schulenberg 2017-09-20 22:20:18 +02:00
parent ae34825f58
commit c74d2632bb
9 changed files with 26 additions and 38 deletions

View File

@ -55,9 +55,6 @@ char *do_browser(char *path)
DIR *dir; DIR *dir;
/* The directory whose contents we are showing. */ /* 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: 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. */
@ -117,7 +114,7 @@ char *do_browser(char *path)
old_selected = selected; old_selected = selected;
kbinput = get_kbinput(edit); kbinput = get_kbinput(edit, ISSET(SHOW_CURSOR));
#ifdef ENABLE_MOUSE #ifdef ENABLE_MOUSE
if (kbinput == KEY_MOUSE) { if (kbinput == KEY_MOUSE) {

View File

@ -56,8 +56,6 @@ 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

@ -158,10 +158,10 @@ void do_help(void)
help_init(); help_init();
inhelp = TRUE; inhelp = TRUE;
location = 0; location = 0;
didfind = 0;
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);
@ -182,9 +182,10 @@ void do_help(void)
while (TRUE) { while (TRUE) {
lastmessage = HUSH; lastmessage = HUSH;
focusing = TRUE; 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); func = parse_help_input(&kbinput);
@ -230,9 +231,6 @@ void do_help(void)
} else } else
unbound_key(kbinput); unbound_key(kbinput);
/* If we searched and found something, let the cursor show it. */
reveal_cursor = (didfind == 1);
currmenu = MHELP; currmenu = MHELP;
edit_refresh(); edit_refresh();

View File

@ -1579,12 +1579,8 @@ 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, and show the cursor while waiting. */
input = get_kbinput(edit, VISIBLE);
/* Read in a keystroke. */
input = get_kbinput(edit);
reveal_cursor = FALSE;
#ifndef NANO_TINY #ifndef NANO_TINY
if (input == KEY_WINCH) if (input == KEY_WINCH)
@ -1597,7 +1593,7 @@ int do_input(bool allow_funcs)
if (do_mouse() == 1) if (do_mouse() == 1)
/* The click was on a shortcut -- read in the character /* The click was on a shortcut -- read in the character
* that it was converted into. */ * that it was converted into. */
input = get_kbinput(edit); input = get_kbinput(edit, BLIND);
else else
/* The click was invalid or has been handled -- get out. */ /* The click was invalid or has been handled -- get out. */
return ERR; return ERR;

View File

@ -135,6 +135,9 @@
#define BACKWARD FALSE #define BACKWARD FALSE
#define FORWARD TRUE #define FORWARD TRUE
#define BLIND FALSE
#define VISIBLE TRUE
/* Enumeration types. */ /* Enumeration types. */
typedef enum { typedef enum {
NIX_FILE, DOS_FILE, MAC_FILE NIX_FILE, DOS_FILE, MAC_FILE

View File

@ -48,7 +48,7 @@ int do_statusbar_input(bool *ran_func, bool *finished)
*finished = FALSE; *finished = FALSE;
/* Read in a character. */ /* Read in a character. */
input = get_kbinput(bottomwin); input = get_kbinput(bottomwin, VISIBLE);
#ifndef NANO_TINY #ifndef NANO_TINY
if (input == KEY_WINCH) if (input == KEY_WINCH)
@ -60,7 +60,7 @@ int do_statusbar_input(bool *ran_func, bool *finished)
* shortcut character. */ * shortcut character. */
if (input == KEY_MOUSE) { if (input == KEY_MOUSE) {
if (do_statusbar_mouse() == 1) if (do_statusbar_mouse() == 1)
input = get_kbinput(bottomwin); input = get_kbinput(bottomwin, BLIND);
else else
return ERR; return ERR;
} }
@ -477,9 +477,6 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
update_the_statusbar(); update_the_statusbar();
while (TRUE) { while (TRUE) {
/* Ensure the cursor is shown when waiting for input. */
reveal_cursor = TRUE;
kbinput = do_statusbar_input(&ran_func, &finished); kbinput = do_statusbar_input(&ran_func, &finished);
#ifndef NANO_TINY #ifndef NANO_TINY
@ -597,8 +594,6 @@ functionptrtype acquire_an_answer(int *actual, bool allow_tabs,
} }
#endif #endif
reveal_cursor = FALSE;
*actual = kbinput; *actual = kbinput;
return func; return func;
@ -746,12 +741,10 @@ int do_yesno_prompt(bool all, const char *msg)
wattroff(bottomwin, interface_color_pair[TITLE_BAR]); wattroff(bottomwin, interface_color_pair[TITLE_BAR]);
wnoutrefresh(bottomwin); wnoutrefresh(bottomwin);
/* When not replacing, show the cursor. */
reveal_cursor = !all;
currmenu = MYESNO; 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); func = func_from_key(&kbinput);

View File

@ -47,7 +47,6 @@ 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;
@ -631,7 +630,7 @@ void dump_filestruct_reverse(void);
void get_key_buffer(WINDOW *win); void get_key_buffer(WINDOW *win);
size_t get_key_buffer_len(void); size_t get_key_buffer_len(void);
void unget_kbinput(int kbinput, bool metakey); 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 parse_kbinput(WINDOW *win);
int arrow_from_abcd(int kbinput); int arrow_from_abcd(int kbinput);
int parse_escape_sequence(WINDOW *win, int kbinput); int parse_escape_sequence(WINDOW *win, int kbinput);

View File

@ -3334,12 +3334,11 @@ void do_linter(void)
bottombars(MLINTER); bottombars(MLINTER);
} }
/* Place and show the cursor to indicate the affected line. */ /* Place the cursor to indicate the affected line. */
place_the_cursor(); place_the_cursor();
reveal_cursor = TRUE;
wnoutrefresh(edit); wnoutrefresh(edit);
kbinput = get_kbinput(bottomwin); kbinput = get_kbinput(bottomwin, VISIBLE);
#ifndef NANO_TINY #ifndef NANO_TINY
if (kbinput == KEY_WINCH) if (kbinput == KEY_WINCH)
@ -3584,7 +3583,6 @@ void do_verbatim_input(void)
* inserted verbatim. */ * inserted verbatim. */
statusbar(_("Verbatim Input")); statusbar(_("Verbatim Input"));
place_the_cursor(); place_the_cursor();
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

@ -49,6 +49,8 @@ static int statusblank = 0;
static bool seen_wide = FALSE; static bool seen_wide = FALSE;
/* Whether we've seen a multicolumn character in the current line. */ /* Whether we've seen a multicolumn character in the current line. */
#endif #endif
static bool reveal_cursor = FALSE;
/* Whether the cursor should be shown when waiting for input. */
/* Control character compatibility: /* 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. */ /* 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; int kbinput = ERR;
reveal_cursor = showcursor;
/* Extract one keystroke from the input stream. */ /* Extract one keystroke from the input stream. */
while (kbinput == ERR) while (kbinput == ERR)
kbinput = parse_kbinput(win); kbinput = parse_kbinput(win);
@ -1529,6 +1533,8 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
{ {
int *kbinput; int *kbinput;
reveal_cursor = TRUE;
/* Read in the first code. */ /* Read in the first code. */
while ((kbinput = get_input(win, 1)) == NULL) while ((kbinput = get_input(win, 1)) == NULL)
; ;