Commit 6da969e4 authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

work around the need to put back the first non-escape character when

reading an escape sequence


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1920 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 146bb602
Showing with 36 additions and 26 deletions
+36 -26
...@@ -36,6 +36,15 @@ CVS code - ...@@ -36,6 +36,15 @@ CVS code -
- winio.c: - winio.c:
unget_kbinput() unget_kbinput()
- New function used as a wrapper for ungetch(). (DLR) - New function used as a wrapper for ungetch(). (DLR)
get_kbinput()
- When reading an escape sequence, set get_verbatim_kbinput()'s
new first parameter to the first character of the sequence
instead of putting that character back and reading the entire
sequence afterwards. (DLR)
get_verbatim_kbinput()
- Add new parameter first. If first isn't ERR, make it the
first character in the returned sequence instead of reading
the first character in via blocking input. (DLR)
get_mouseinput() get_mouseinput()
- Consolidate two if statements to increase efficiency. (DLR) - Consolidate two if statements to increase efficiency. (DLR)
- Check kbinput against metaval instead of (erroneously) ctrlval - Check kbinput against metaval instead of (erroneously) ctrlval
......
...@@ -946,7 +946,7 @@ void do_verbatim_input(void) ...@@ -946,7 +946,7 @@ void do_verbatim_input(void)
statusbar(_("Verbatim input")); statusbar(_("Verbatim input"));
v_kbinput = get_verbatim_kbinput(edit, v_kbinput, &v_len, TRUE); v_kbinput = get_verbatim_kbinput(edit, ERR, v_kbinput, &v_len, TRUE);
/* Turn on DISABLE_CURPOS while inserting character(s) and turn it /* Turn on DISABLE_CURPOS while inserting character(s) and turn it
* off afterwards, so that if constant cursor position display is * off afterwards, so that if constant cursor position display is
......
...@@ -508,8 +508,8 @@ int get_control_kbinput(int kbinput); ...@@ -508,8 +508,8 @@ int get_control_kbinput(int kbinput);
int get_escape_seq_kbinput(int *escape_seq, size_t es_len, bool int get_escape_seq_kbinput(int *escape_seq, size_t es_len, bool
*ignore_seq); *ignore_seq);
int get_escape_seq_abcd(int kbinput); int get_escape_seq_abcd(int kbinput);
int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len, int *get_verbatim_kbinput(WINDOW *win, int first, int *v_kbinput, size_t
bool allow_ascii); *v_len, bool allow_ascii);
int get_untranslated_kbinput(int kbinput, size_t position, bool int get_untranslated_kbinput(int kbinput, size_t position, bool
allow_ascii allow_ascii
#ifndef NANO_SMALL #ifndef NANO_SMALL
......
...@@ -145,26 +145,22 @@ int get_kbinput(WINDOW *win, bool *meta_key) ...@@ -145,26 +145,22 @@ int get_kbinput(WINDOW *win, bool *meta_key)
int *escape_seq = NULL; int *escape_seq = NULL;
size_t es_len; size_t es_len;
/* First, assume that we got a meta sequence. Set meta_key /* Read in the complete escape sequence, putting the initial
* to TRUE and save the character we got as the result. We * non-escape at the beginning of it. */
* do this so that if the keyboard buffer is full when we escape_seq = get_verbatim_kbinput(win, kbinput, escape_seq,
* send back the character we got below (in which case we'll &es_len, FALSE);
* lose that character), it'll still be properly interpreted
* as a meta sequence. */ /* If the escape sequence is one character long, set
*meta_key = TRUE; * meta_key to TRUE, make the non-escape character
retval = tolower(kbinput); * lowercase, and save that as the result. */
if (es_len == 1) {
/* Next, send back the character we got and read in the *meta_key = TRUE;
* complete escape sequence. */ retval = tolower(kbinput);
unget_kbinput(kbinput, FALSE);
escape_seq = get_verbatim_kbinput(win, escape_seq, &es_len,
FALSE);
/* If the escape sequence is more than one character /* If the escape sequence is more than one character
* long, set meta_key to FALSE, translate the escape * long, set meta_key to FALSE, translate the escape
* sequence into the corresponding key value, and save * sequence into the corresponding key value, and save
* that as the result. */ * that as the result. */
if (es_len > 1) { } else if (es_len > 1) {
bool ignore_seq; bool ignore_seq;
*meta_key = FALSE; *meta_key = FALSE;
...@@ -1078,10 +1074,11 @@ int get_escape_seq_abcd(int kbinput) ...@@ -1078,10 +1074,11 @@ int get_escape_seq_abcd(int kbinput)
} }
/* Read in a string of input characters (e.g. an escape sequence) /* Read in a string of input characters (e.g. an escape sequence)
* verbatim. Store the string in v_kbinput and return the length * verbatim. If first isn't ERR, make it the first character of the
* of the string in v_len. Assume nodelay(win) is FALSE. */ * string. Store the string in v_kbinput and return the length of the
int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len, * string in v_len. Assume nodelay(win) is FALSE. */
bool allow_ascii) int *get_verbatim_kbinput(WINDOW *win, int first, int *v_kbinput, size_t
*v_len, bool allow_ascii)
{ {
int kbinput; int kbinput;
size_t i = 0, v_newlen = 0; size_t i = 0, v_newlen = 0;
...@@ -1100,10 +1097,14 @@ int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len, ...@@ -1100,10 +1097,14 @@ int *get_verbatim_kbinput(WINDOW *win, int *v_kbinput, size_t *v_len,
disable_flow_control(); disable_flow_control();
keypad(win, FALSE); keypad(win, FALSE);
/* Read the first character using blocking input, since using /* If first is ERR, read the first character using blocking input,
* non-blocking input will eat up all unused CPU. Then increment * since using non-blocking input will eat up all unused CPU.
* Otherwise, treat first as the first character. Then increment
* v_len and save the character in v_kbinput. */ * v_len and save the character in v_kbinput. */
kbinput = wgetch(win); if (first == ERR)
kbinput = wgetch(win);
else
kbinput = first;
(*v_len)++; (*v_len)++;
v_kbinput[0] = kbinput; v_kbinput[0] = kbinput;
#ifdef DEBUG #ifdef DEBUG
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment