mirror of
git://git.sv.gnu.org/nano.git
synced 2024-11-22 21:01:24 +03:00
tweaks: rename a variable, for clarity and contrast
This commit is contained in:
parent
2fd30ee095
commit
bdf64d660b
61
src/winio.c
61
src/winio.c
@ -44,8 +44,8 @@
|
|||||||
|
|
||||||
static int *key_buffer = NULL;
|
static int *key_buffer = NULL;
|
||||||
/* A buffer for the keystrokes that haven't been handled yet. */
|
/* A buffer for the keystrokes that haven't been handled yet. */
|
||||||
static size_t key_buffer_len = 0;
|
static size_t waiting_codes = 0;
|
||||||
/* The length of the keystroke buffer. */
|
/* The number of key codes waiting in the keystroke buffer. */
|
||||||
static int digit_count = 0;
|
static int digit_count = 0;
|
||||||
/* How many digits of a three-digit character code we've eaten. */
|
/* How many digits of a three-digit character code we've eaten. */
|
||||||
static bool reveal_cursor = FALSE;
|
static bool reveal_cursor = FALSE;
|
||||||
@ -121,11 +121,11 @@ void run_macro(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
key_buffer = nrealloc(key_buffer, macro_length * sizeof(int));
|
key_buffer = nrealloc(key_buffer, macro_length * sizeof(int));
|
||||||
key_buffer_len = macro_length;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < macro_length; i++)
|
for (size_t i = 0; i < macro_length; i++)
|
||||||
key_buffer[i] = macro_buffer[i];
|
key_buffer[i] = macro_buffer[i];
|
||||||
|
|
||||||
|
waiting_codes = macro_length;
|
||||||
mute_modifiers = TRUE;
|
mute_modifiers = TRUE;
|
||||||
}
|
}
|
||||||
#endif /* !NANO_TINY */
|
#endif /* !NANO_TINY */
|
||||||
@ -245,7 +245,7 @@ void read_keys_from(WINDOW *win)
|
|||||||
/* Initiate the keystroke buffer, and save the keycode in it. */
|
/* Initiate the keystroke buffer, and save the keycode in it. */
|
||||||
key_buffer = nrealloc(key_buffer, sizeof(int));
|
key_buffer = nrealloc(key_buffer, sizeof(int));
|
||||||
key_buffer[0] = input;
|
key_buffer[0] = input;
|
||||||
key_buffer_len = 1;
|
waiting_codes = 1;
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* Cancel the highlighting of a search match, if there still is one. */
|
/* Cancel the highlighting of a search match, if there still is one. */
|
||||||
@ -279,9 +279,8 @@ void read_keys_from(WINDOW *win)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* Extend the keystroke buffer, and save the keycode at its end. */
|
/* Extend the keystroke buffer, and save the keycode at its end. */
|
||||||
key_buffer_len++;
|
key_buffer = nrealloc(key_buffer, ++waiting_codes * sizeof(int));
|
||||||
key_buffer = nrealloc(key_buffer, key_buffer_len * sizeof(int));
|
key_buffer[waiting_codes - 1] = input;
|
||||||
key_buffer[key_buffer_len - 1] = input;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Restore blocking-input mode. */
|
/* Restore blocking-input mode. */
|
||||||
@ -289,32 +288,32 @@ void read_keys_from(WINDOW *win)
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "\nSequence of hex codes:");
|
fprintf(stderr, "\nSequence of hex codes:");
|
||||||
for (size_t i = 0; i < key_buffer_len; i++)
|
for (size_t i = 0; i < waiting_codes; i++)
|
||||||
fprintf(stderr, " %3x", key_buffer[i]);
|
fprintf(stderr, " %3x", key_buffer[i]);
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the length of the keystroke buffer. */
|
/* Return the number of key codes waiting in the keystroke buffer. */
|
||||||
size_t get_key_buffer_len(void)
|
size_t get_key_buffer_len(void)
|
||||||
{
|
{
|
||||||
return key_buffer_len;
|
return waiting_codes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add the given keycode to the front of the keystroke buffer. */
|
/* Add the given keycode to the front of the keystroke buffer. */
|
||||||
void put_back(int keycode)
|
void put_back(int keycode)
|
||||||
{
|
{
|
||||||
/* If the keystroke buffer is at maximum capacity, don't add anything. */
|
/* If the keystroke buffer is at maximum capacity, don't add anything. */
|
||||||
if (key_buffer_len + 1 < key_buffer_len)
|
if (waiting_codes + 1 < waiting_codes)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Extend the keystroke buffer to make room for the extra keycode. */
|
/* Extend the keystroke buffer to make room for the extra keycode. */
|
||||||
key_buffer = nrealloc(key_buffer, ++key_buffer_len * sizeof(int));
|
key_buffer = nrealloc(key_buffer, ++waiting_codes * sizeof(int));
|
||||||
|
|
||||||
/* If the keystroke buffer wasn't empty before, move all the
|
/* If the keystroke buffer wasn't empty before, move all the
|
||||||
* existing content one step further away. */
|
* existing content one step further away. */
|
||||||
if (key_buffer_len > 1)
|
if (waiting_codes > 1)
|
||||||
memmove(key_buffer + 1, key_buffer, (key_buffer_len - 1) * sizeof(int));
|
memmove(key_buffer + 1, key_buffer, (waiting_codes - 1) * sizeof(int));
|
||||||
|
|
||||||
*key_buffer = keycode;
|
*key_buffer = keycode;
|
||||||
}
|
}
|
||||||
@ -337,18 +336,18 @@ int get_input(WINDOW *win)
|
|||||||
{
|
{
|
||||||
int input;
|
int input;
|
||||||
|
|
||||||
if (key_buffer_len == 0 && win != NULL)
|
if (waiting_codes == 0 && win != NULL)
|
||||||
read_keys_from(win);
|
read_keys_from(win);
|
||||||
|
|
||||||
if (key_buffer_len == 0)
|
if (waiting_codes == 0)
|
||||||
return ERR;
|
return ERR;
|
||||||
|
|
||||||
/* Take the first code from the head of the keystroke buffer. */
|
/* Take the first code from the head of the keystroke buffer. */
|
||||||
input = key_buffer[0];
|
input = key_buffer[0];
|
||||||
|
|
||||||
/* If the buffer contains more codes, move them to the front. */
|
/* If the buffer contains more codes, move them to the front. */
|
||||||
if (--key_buffer_len > 0)
|
if (--waiting_codes > 0)
|
||||||
memmove(key_buffer, key_buffer + 1, key_buffer_len * sizeof(int));
|
memmove(key_buffer, key_buffer + 1, waiting_codes * sizeof(int));
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
@ -839,13 +838,13 @@ int parse_escape_sequence(int starter)
|
|||||||
int keycode = 0;
|
int keycode = 0;
|
||||||
|
|
||||||
if (starter == 'O')
|
if (starter == 'O')
|
||||||
keycode = convert_SS3_sequence(key_buffer, key_buffer_len, &consumed);
|
keycode = convert_SS3_sequence(key_buffer, waiting_codes, &consumed);
|
||||||
else if (starter == '[')
|
else if (starter == '[')
|
||||||
keycode = convert_CSI_sequence(key_buffer, key_buffer_len, &consumed);
|
keycode = convert_CSI_sequence(key_buffer, waiting_codes, &consumed);
|
||||||
|
|
||||||
/* Remove the consumed sequence bytes from the keystroke buffer. */
|
/* Remove the consumed sequence bytes from the keystroke buffer. */
|
||||||
key_buffer_len -= consumed;
|
waiting_codes -= consumed;
|
||||||
memmove(key_buffer, key_buffer + consumed, key_buffer_len * sizeof(int));
|
memmove(key_buffer, key_buffer + consumed, waiting_codes * sizeof(int));
|
||||||
|
|
||||||
return keycode;
|
return keycode;
|
||||||
}
|
}
|
||||||
@ -937,7 +936,7 @@ int parse_kbinput(WINDOW *win)
|
|||||||
* Then increment the counter, rolling around on three escapes. */
|
* Then increment the counter, rolling around on three escapes. */
|
||||||
if (keycode == ESC_CODE) {
|
if (keycode == ESC_CODE) {
|
||||||
first_escape_was_alone = last_escape_was_alone;
|
first_escape_was_alone = last_escape_was_alone;
|
||||||
last_escape_was_alone = (key_buffer_len == 0);
|
last_escape_was_alone = (waiting_codes == 0);
|
||||||
if (digit_count > 0) {
|
if (digit_count > 0) {
|
||||||
digit_count = 0;
|
digit_count = 0;
|
||||||
escapes = 1;
|
escapes = 1;
|
||||||
@ -963,14 +962,14 @@ int parse_kbinput(WINDOW *win)
|
|||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_UTF8
|
#ifdef ENABLE_UTF8
|
||||||
else if (0xC0 <= keycode && keycode <= 0xFF && using_utf8()) {
|
else if (0xC0 <= keycode && keycode <= 0xFF && using_utf8()) {
|
||||||
while (key_buffer_len > 0 && 0x80 <= *key_buffer && *key_buffer <= 0xBF)
|
while (waiting_codes && 0x80 <= *key_buffer && *key_buffer <= 0xBF)
|
||||||
get_input(NULL);
|
get_input(NULL);
|
||||||
return FOREIGN_SEQUENCE;
|
return FOREIGN_SEQUENCE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (keycode < 0x20 && !last_escape_was_alone)
|
else if (keycode < 0x20 && !last_escape_was_alone)
|
||||||
meta_key = TRUE;
|
meta_key = TRUE;
|
||||||
} else if (key_buffer_len == 0 || *key_buffer == ESC_CODE ||
|
} else if (waiting_codes == 0 || *key_buffer == ESC_CODE ||
|
||||||
(keycode != 'O' && keycode != '[')) {
|
(keycode != 'O' && keycode != '[')) {
|
||||||
if (!shifted_metas)
|
if (!shifted_metas)
|
||||||
keycode = tolower(keycode);
|
keycode = tolower(keycode);
|
||||||
@ -979,7 +978,7 @@ int parse_kbinput(WINDOW *win)
|
|||||||
keycode = parse_escape_sequence(keycode);
|
keycode = parse_escape_sequence(keycode);
|
||||||
} else {
|
} else {
|
||||||
escapes = 0;
|
escapes = 0;
|
||||||
if (keycode == '[' && key_buffer_len > 0 &&
|
if (keycode == '[' && waiting_codes &&
|
||||||
(('A' <= *key_buffer && *key_buffer <= 'D') ||
|
(('A' <= *key_buffer && *key_buffer <= 'D') ||
|
||||||
('a' <= *key_buffer && *key_buffer <= 'd'))) {
|
('a' <= *key_buffer && *key_buffer <= 'd'))) {
|
||||||
/* An iTerm2/Eterm/rxvt double-escape sequence: Esc Esc [ X
|
/* An iTerm2/Eterm/rxvt double-escape sequence: Esc Esc [ X
|
||||||
@ -996,7 +995,7 @@ int parse_kbinput(WINDOW *win)
|
|||||||
case 'd': shift_held = TRUE; return KEY_END;
|
case 'd': shift_held = TRUE; return KEY_END;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else if (key_buffer_len > 0 && *key_buffer != ESC_CODE &&
|
} else if (waiting_codes && *key_buffer != ESC_CODE &&
|
||||||
(keycode == '[' || keycode == 'O')) {
|
(keycode == '[' || keycode == 'O')) {
|
||||||
keycode = parse_escape_sequence(keycode);
|
keycode = parse_escape_sequence(keycode);
|
||||||
meta_key = TRUE;
|
meta_key = TRUE;
|
||||||
@ -1420,12 +1419,12 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
|
|||||||
if (unicode == INVALID_DIGIT) {
|
if (unicode == INVALID_DIGIT) {
|
||||||
if (keycode == ESC_CODE) {
|
if (keycode == ESC_CODE) {
|
||||||
get_input(NULL);
|
get_input(NULL);
|
||||||
while (key_buffer_len > 0 && 0x1F < *key_buffer && *key_buffer < 0x40)
|
while (waiting_codes && 0x1F < *key_buffer && *key_buffer < 0x40)
|
||||||
get_input(NULL);
|
get_input(NULL);
|
||||||
if (key_buffer_len > 0 && 0x3F < *key_buffer && *key_buffer < 0x7F)
|
if (waiting_codes && 0x3F < *key_buffer && *key_buffer < 0x7F)
|
||||||
get_input(NULL);
|
get_input(NULL);
|
||||||
} else if (0xC0 <= keycode && keycode <= 0xFF)
|
} else if (0xC0 <= keycode && keycode <= 0xFF)
|
||||||
while (key_buffer_len > 0 && 0x7F < *key_buffer && *key_buffer < 0xC0)
|
while (waiting_codes && 0x7F < *key_buffer && *key_buffer < 0xC0)
|
||||||
get_input(NULL);
|
get_input(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1447,7 +1446,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
|
|||||||
|
|
||||||
/* In case of an escape, take also a second code, as it might be another
|
/* In case of an escape, take also a second code, as it might be another
|
||||||
* escape (on iTerm2/rxvt) or a control code (for M-Bsp and M-Enter). */
|
* escape (on iTerm2/rxvt) or a control code (for M-Bsp and M-Enter). */
|
||||||
if (keycode == ESC_CODE && key_buffer_len > 0) {
|
if (keycode == ESC_CODE && waiting_codes) {
|
||||||
yield[1] = get_input(NULL);
|
yield[1] = get_input(NULL);
|
||||||
*count = 2;
|
*count = 2;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user