add unget_kbinput(), a wrapper for ungetch()

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1911 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2004-08-25 16:37:06 +00:00
parent a0b5ba2f7f
commit dfca1c4ea6
5 changed files with 26 additions and 20 deletions

View File

@ -16,6 +16,8 @@ CVS code -
parsing the numeric argument after "tabsize" works properly
again. (DLR, found by Mike Frysinger)
- winio.c:
unget_kbinput()
- New function used as a wrapper for ungetch(). (DLR)
get_mouseinput()
- Consolidate two if statements to increase efficiency. (DLR)
do_yesno()

View File

@ -2619,7 +2619,7 @@ char *do_browser(const char *inpath)
if (selected > numents - 1)
selected = numents - 1;
else if (selectedbackup == selected)
ungetch('s'); /* Unget the 'select' key */
unget_kbinput('s', FALSE); /* Unget the 'select' key */
} else { /* Must be clicking a shortcut */
int mouse_x, mouse_y;
get_mouseinput(&mouse_x, &mouse_y, TRUE);

View File

@ -2609,9 +2609,7 @@ void do_justify(bool full_justify)
edit_refresh();
} else {
placewewant = 0;
ungetch(kbinput);
if (meta_key)
ungetch(NANO_CONTROL_3);
unget_kbinput(kbinput, meta_key);
}
cutbuffer = cutbuffer_save;

View File

@ -491,6 +491,7 @@ int check_wildcard_match(const char *text, const char *pattern);
#ifndef NANO_SMALL
void reset_kbinput(void);
#endif
void unget_kbinput(int kbinput, bool meta_key);
int get_kbinput(WINDOW *win, bool *meta_key);
int get_translated_kbinput(int kbinput, bool *es
#ifndef NANO_SMALL

View File

@ -99,6 +99,15 @@ void reset_kbinput(void)
}
#endif
/* Put back the input character stored in kbinput. If meta_key is TRUE,
* put back the Escape character after putting back kbinput. */
void unget_kbinput(int kbinput, bool meta_key)
{
ungetch(kbinput);
if (meta_key)
ungetch(NANO_CONTROL_3);
}
/* Read in a single input character. If it's ignored, swallow it and go
* on. Otherwise, try to translate it from ASCII, extended keypad
* values, and/or escape sequences. Set meta_key to TRUE when we get a
@ -147,7 +156,7 @@ int get_kbinput(WINDOW *win, bool *meta_key)
/* Next, send back the character we got and read in the
* complete escape sequence. */
ungetch(kbinput);
unget_kbinput(kbinput, FALSE);
escape_seq = get_verbatim_kbinput(win, escape_seq, &es_len,
FALSE);
@ -166,7 +175,7 @@ int get_kbinput(WINDOW *win, bool *meta_key)
/* This escape sequence is unrecognized. Send it
* back. */
for (; es_len > 1; es_len--)
ungetch(escape_seq[es_len - 1]);
unget_kbinput(escape_seq[es_len - 1], FALSE);
retval = escape_seq[0];
}
}
@ -1243,9 +1252,9 @@ int get_untranslated_kbinput(int kbinput, size_t position, bool
* coordinates where it took place in mouse_x and mouse_y. After that,
* assuming allow_shortcuts is FALSE, if the shortcut list on the
* bottom two lines of the screen is visible and the mouse event took
* place on it, figure out which shortcut was clicked and ungetch() the
* equivalent keystroke(s). Return FALSE if no keystrokes were
* ungetch()ed, or TRUE if at least one was. Assume that KEY_MOUSE has
* place on it, figure out which shortcut was clicked and put back the
* equivalent keystroke(s). Return FALSE if no keystrokes were
* put back, or TRUE if at least one was. Assume that KEY_MOUSE has
* already been read in. */
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
{
@ -1265,7 +1274,7 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
/* If we're allowing shortcuts, the current shortcut list is being
* displayed on the last two lines of the screen, and the mouse
* event took place inside it, we need to figure out which shortcut
* was clicked and ungetch() the equivalent keystroke(s) for it. */
* was clicked and put back the equivalent keystroke(s) for it. */
if (allow_shortcuts && !ISSET(NO_HELP) && wenclose(bottomwin,
*mouse_y, *mouse_x)) {
int i, j;
@ -1306,16 +1315,12 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
for (; j > 0; j--)
s = s->next;
/* And ungetch() the equivalent control key. If it's a meta key
* sequence, we need to ungetch() Escape too. Assume that the
* shortcut has an equivalent control key, meta key sequence, or
* both. */
/* And put back the equivalent key. Assume that the shortcut
* has an equivalent control key, meta key sequence, or both. */
if (s->ctrlval != NANO_NO_KEY)
ungetch(s->ctrlval);
else if (s->ctrlval != NANO_NO_KEY) {
ungetch(s->metaval);
ungetch(NANO_CONTROL_3);
}
unget_kbinput(s->ctrlval, FALSE);
else if (s->ctrlval != NANO_NO_KEY)
unget_kbinput(s->metaval, TRUE);
return TRUE;
}
@ -2022,7 +2027,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
#endif
if (meta_key && (kbinput == t->metaval || kbinput == t->miscval))
/* We hit a meta key. Do like above. We don't
* just ungetch() the letter and let it get
* just put back the letter and let it get
* caught above cause that screws the
* keypad... */
return kbinput;