add a func_key flag to the low-level input functions and the currently
existing high-level input functions, to indicate extended keypad values git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1943 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
72d8e54f6e
commit
eb16f43cf9
|
@ -49,6 +49,11 @@ CVS code -
|
||||||
changes to terminal_init(). (DLR)
|
changes to terminal_init(). (DLR)
|
||||||
- Remove redundant include of limits.h from nano.c. nano.c
|
- Remove redundant include of limits.h from nano.c. nano.c
|
||||||
includes nano.h and nano.h includes limits.h. (DLR)
|
includes nano.h and nano.h includes limits.h. (DLR)
|
||||||
|
- Add a func_key flag to the low-level input functions and the
|
||||||
|
currently existing high-level input functions, to indicate
|
||||||
|
extended keypad values. This is needed for UTF-8 support.
|
||||||
|
Changes to get_kbinput(), get_translated_kbinput(),
|
||||||
|
get_shortcut(), get_edit_input(), etc. (DLR)
|
||||||
- files.c:
|
- files.c:
|
||||||
do_insertfile()
|
do_insertfile()
|
||||||
- Readd the NANO_SMALL #ifdef around the start_again: label to
|
- Readd the NANO_SMALL #ifdef around the start_again: label to
|
||||||
|
|
|
@ -2485,7 +2485,7 @@ char *do_browser(const char *inpath)
|
||||||
int numents = 0, i = 0, j = 0, longest = 0, abort = 0, col = 0;
|
int numents = 0, i = 0, j = 0, longest = 0, abort = 0, col = 0;
|
||||||
int selected = 0, editline = 0, width = 0, filecols = 0, lineno = 0;
|
int selected = 0, editline = 0, width = 0, filecols = 0, lineno = 0;
|
||||||
int kbinput = ERR;
|
int kbinput = ERR;
|
||||||
bool meta_key;
|
bool meta_key, func_key;
|
||||||
char **filelist = (char **)NULL;
|
char **filelist = (char **)NULL;
|
||||||
#ifndef DISABLE_MOUSE
|
#ifndef DISABLE_MOUSE
|
||||||
MEVENT mevent;
|
MEVENT mevent;
|
||||||
|
@ -2808,7 +2808,8 @@ char *do_browser(const char *inpath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wrefresh(edit);
|
wrefresh(edit);
|
||||||
} while ((kbinput = get_kbinput(edit, &meta_key)) != NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
|
} while ((kbinput = get_kbinput(edit, &meta_key, &func_key)) !=
|
||||||
|
NANO_EXIT_KEY && kbinput != NANO_EXIT_FKEY);
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
blank_edit();
|
blank_edit();
|
||||||
titlebar(NULL);
|
titlebar(NULL);
|
||||||
|
|
|
@ -2343,7 +2343,7 @@ void do_justify(bool full_justify)
|
||||||
int mark_beginx_save = mark_beginx;
|
int mark_beginx_save = mark_beginx;
|
||||||
#endif
|
#endif
|
||||||
int kbinput;
|
int kbinput;
|
||||||
bool meta_key;
|
bool meta_key, func_key;
|
||||||
|
|
||||||
/* If we're justifying the entire file, start at the beginning. */
|
/* If we're justifying the entire file, start at the beginning. */
|
||||||
if (full_justify)
|
if (full_justify)
|
||||||
|
@ -2604,7 +2604,7 @@ void do_justify(bool full_justify)
|
||||||
|
|
||||||
/* Now get a keystroke and see if it's unjustify; if not, unget the
|
/* Now get a keystroke and see if it's unjustify; if not, unget the
|
||||||
* keystroke and return. */
|
* keystroke and return. */
|
||||||
kbinput = get_edit_input(&meta_key, FALSE);
|
kbinput = get_edit_input(&meta_key, &func_key, FALSE);
|
||||||
|
|
||||||
if (!meta_key && kbinput == NANO_UNJUSTIFY_KEY) {
|
if (!meta_key && kbinput == NANO_UNJUSTIFY_KEY) {
|
||||||
/* Restore the justify we just did (ungrateful user!). */
|
/* Restore the justify we just did (ungrateful user!). */
|
||||||
|
@ -2998,7 +2998,7 @@ int main(int argc, char **argv)
|
||||||
#endif
|
#endif
|
||||||
int kbinput;
|
int kbinput;
|
||||||
/* Input from keyboard. */
|
/* Input from keyboard. */
|
||||||
bool meta_key;
|
bool meta_key, func_key;
|
||||||
#ifdef HAVE_GETOPT_LONG
|
#ifdef HAVE_GETOPT_LONG
|
||||||
const struct option long_options[] = {
|
const struct option long_options[] = {
|
||||||
{"help", 0, 0, 'h'},
|
{"help", 0, 0, 'h'},
|
||||||
|
@ -3496,7 +3496,7 @@ int main(int argc, char **argv)
|
||||||
currshortcut = main_list;
|
currshortcut = main_list;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
kbinput = get_edit_input(&meta_key, TRUE);
|
kbinput = get_edit_input(&meta_key, &func_key, TRUE);
|
||||||
|
|
||||||
/* Last gasp, stuff that's not in the main lists. */
|
/* Last gasp, stuff that's not in the main lists. */
|
||||||
if (kbinput != ERR && !is_cntrl_char(kbinput)) {
|
if (kbinput != ERR && !is_cntrl_char(kbinput)) {
|
||||||
|
|
|
@ -499,8 +499,8 @@ int check_wildcard_match(const char *text, const char *pattern);
|
||||||
void reset_kbinput(void);
|
void reset_kbinput(void);
|
||||||
#endif
|
#endif
|
||||||
void unget_kbinput(int kbinput, bool meta_key);
|
void unget_kbinput(int kbinput, bool meta_key);
|
||||||
int get_kbinput(WINDOW *win, bool *meta_key);
|
int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key);
|
||||||
int get_translated_kbinput(int kbinput, bool *es
|
int get_translated_kbinput(int kbinput, bool *func_key, bool *es
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
, bool reset
|
, bool reset
|
||||||
#endif
|
#endif
|
||||||
|
@ -526,11 +526,11 @@ int get_untranslated_kbinput(int kbinput, size_t position, bool
|
||||||
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
|
bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts);
|
||||||
#endif
|
#endif
|
||||||
const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
||||||
*meta_key);
|
*meta_key, bool *func_key);
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
const toggle *get_toggle(int kbinput, bool meta_key);
|
const toggle *get_toggle(int kbinput, bool meta_key);
|
||||||
#endif
|
#endif
|
||||||
int get_edit_input(bool *meta_key, bool allow_funcs);
|
int get_edit_input(bool *meta_key, bool *func_key, bool allow_funcs);
|
||||||
#ifndef DISABLE_MOUSE
|
#ifndef DISABLE_MOUSE
|
||||||
bool get_edit_mouse(void);
|
bool get_edit_mouse(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
68
src/winio.c
68
src/winio.c
|
@ -93,7 +93,7 @@ static int statblank = 0; /* Number of keystrokes left after
|
||||||
/* Reset all the input routines that rely on character sequences. */
|
/* Reset all the input routines that rely on character sequences. */
|
||||||
void reset_kbinput(void)
|
void reset_kbinput(void)
|
||||||
{
|
{
|
||||||
get_translated_kbinput(0, NULL, TRUE);
|
get_translated_kbinput(0, NULL, NULL, TRUE);
|
||||||
get_ascii_kbinput(0, 0, TRUE);
|
get_ascii_kbinput(0, 0, TRUE);
|
||||||
get_untranslated_kbinput(0, 0, FALSE, TRUE);
|
get_untranslated_kbinput(0, 0, FALSE, TRUE);
|
||||||
}
|
}
|
||||||
|
@ -111,12 +111,13 @@ void unget_kbinput(int kbinput, bool meta_key)
|
||||||
/* Read in a single input character. If it's ignored, swallow it and go
|
/* Read in a single input character. If it's ignored, swallow it and go
|
||||||
* on. Otherwise, try to translate it from ASCII, extended keypad
|
* on. Otherwise, try to translate it from ASCII, extended keypad
|
||||||
* values, and/or escape sequences. Set meta_key to TRUE when we get a
|
* values, and/or escape sequences. Set meta_key to TRUE when we get a
|
||||||
* meta sequence. Supported extended keypad values consist of [arrow
|
* meta sequence, and set func_key to TRUE when we get an extended
|
||||||
|
* keypad sequence. Supported extended keypad values consist of [arrow
|
||||||
* key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace, the
|
* key], Ctrl-[arrow key], Shift-[arrow key], Enter, Backspace, the
|
||||||
* editing keypad (Insert, Delete, Home, End, PageUp, and PageDown), the
|
* editing keypad (Insert, Delete, Home, End, PageUp, and PageDown), the
|
||||||
* function keypad (F1-F14), and the numeric keypad with NumLock off.
|
* function keypad (F1-F14), and the numeric keypad with NumLock off.
|
||||||
* Assume nodelay(win) is FALSE. */
|
* Assume nodelay(win) is FALSE. */
|
||||||
int get_kbinput(WINDOW *win, bool *meta_key)
|
int get_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
|
||||||
{
|
{
|
||||||
int kbinput, retval = ERR;
|
int kbinput, retval = ERR;
|
||||||
bool es;
|
bool es;
|
||||||
|
@ -126,6 +127,7 @@ int get_kbinput(WINDOW *win, bool *meta_key)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*meta_key = FALSE;
|
*meta_key = FALSE;
|
||||||
|
*func_key = FALSE;
|
||||||
|
|
||||||
while (retval == ERR) {
|
while (retval == ERR) {
|
||||||
/* Read a character using blocking input, since using
|
/* Read a character using blocking input, since using
|
||||||
|
@ -133,7 +135,7 @@ int get_kbinput(WINDOW *win, bool *meta_key)
|
||||||
* to get_translated_kbinput(). Continue until we get a
|
* to get_translated_kbinput(). Continue until we get a
|
||||||
* complete sequence. */
|
* complete sequence. */
|
||||||
kbinput = wgetch(win);
|
kbinput = wgetch(win);
|
||||||
retval = get_translated_kbinput(kbinput, &es
|
retval = get_translated_kbinput(kbinput, func_key, &es
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
, FALSE
|
, FALSE
|
||||||
#endif
|
#endif
|
||||||
|
@ -180,7 +182,7 @@ int get_kbinput(WINDOW *win, bool *meta_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "get_kbinput(): kbinput = %d, meta_key = %d\n", kbinput, (int)*meta_key);
|
fprintf(stderr, "get_kbinput(): kbinput = %d, meta_key = %d, func_key = %d\n", kbinput, (int)*meta_key, (int)*func_key);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
|
@ -191,9 +193,10 @@ int get_kbinput(WINDOW *win, bool *meta_key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Translate acceptable ASCII, extended keypad values, and escape
|
/* Translate acceptable ASCII, extended keypad values, and escape
|
||||||
* sequences into their corresponding key values. Set es to TRUE when
|
* sequences into their corresponding key values. Set func_key to TRUE
|
||||||
* we get an escape sequence. Assume nodelay(win) is FALSE. */
|
* when we get an extended keypad value, and set es to TRUE when we get
|
||||||
int get_translated_kbinput(int kbinput, bool *es
|
* an escape sequence. Assume nodelay(win) is FALSE. */
|
||||||
|
int get_translated_kbinput(int kbinput, bool *func_key, bool *es
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
, bool reset
|
, bool reset
|
||||||
#endif
|
#endif
|
||||||
|
@ -211,6 +214,7 @@ int get_translated_kbinput(int kbinput, bool *es
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
*func_key = FALSE;
|
||||||
*es = FALSE;
|
*es = FALSE;
|
||||||
|
|
||||||
switch (kbinput) {
|
switch (kbinput) {
|
||||||
|
@ -420,9 +424,13 @@ int get_translated_kbinput(int kbinput, bool *es
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If the result is outside the ASCII range, set func_key to TRUE. */
|
||||||
|
if (retval > 255)
|
||||||
|
*func_key = TRUE;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "get_translated_kbinput(): kbinput = %d, es = %d, escapes = %d, ascii_digits = %lu, retval = %d\n", kbinput, (int)*es, escapes, (unsigned long)ascii_digits, retval);
|
fprintf(stderr, "get_translated_kbinput(): kbinput = %d, func_key = %d, es = %d, escapes = %d, ascii_digits = %lu, retval = %d\n", kbinput, (int)*func_key, (int)*es, escapes, (unsigned long)ascii_digits, retval);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Return the result. */
|
/* Return the result. */
|
||||||
|
@ -1337,7 +1345,7 @@ bool get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts)
|
||||||
#endif /* !DISABLE_MOUSE */
|
#endif /* !DISABLE_MOUSE */
|
||||||
|
|
||||||
const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
||||||
*meta_key)
|
*meta_key, bool *func_key)
|
||||||
{
|
{
|
||||||
const shortcut *s = s_list;
|
const shortcut *s = s_list;
|
||||||
size_t slen = length_of_list(s_list);
|
size_t slen = length_of_list(s_list);
|
||||||
|
@ -1348,14 +1356,17 @@ const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
||||||
*
|
*
|
||||||
* 1. The key exists.
|
* 1. The key exists.
|
||||||
* 2. The key is a control key in the shortcut list.
|
* 2. The key is a control key in the shortcut list.
|
||||||
* 3. The key is a function key in the shortcut list.
|
* 3. meta_key is TRUE and the key is the primary or
|
||||||
* 4. meta_key is TRUE and the key is a meta sequence.
|
* miscellaneous meta sequence in the shortcut list.
|
||||||
* 5. meta_key is TRUE and the key is the other meta sequence in
|
* 4. func_key is TRUE and the key is a function key in the
|
||||||
* the shortcut list. */
|
* shortcut list. */
|
||||||
|
|
||||||
if (kbinput != NANO_NO_KEY && ((*meta_key == FALSE &&
|
if (kbinput != NANO_NO_KEY && ((*meta_key == FALSE &&
|
||||||
((kbinput == s->ctrlval || kbinput == s->funcval))) ||
|
*func_key == FALSE && kbinput == s->ctrlval) ||
|
||||||
(*meta_key == TRUE && (kbinput == s->metaval ||
|
(*meta_key == TRUE && *func_key == FALSE &&
|
||||||
kbinput == s->miscval)))) {
|
(kbinput == s->metaval || kbinput == s->miscval)) ||
|
||||||
|
(*meta_key == FALSE && *func_key == TRUE &&
|
||||||
|
kbinput == s->funcval))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1364,7 +1375,7 @@ const shortcut *get_shortcut(const shortcut *s_list, int kbinput, bool
|
||||||
|
|
||||||
/* Translate the shortcut to either its control key or its meta key
|
/* Translate the shortcut to either its control key or its meta key
|
||||||
* equivalent. Assume that the shortcut has an equivalent control
|
* equivalent. Assume that the shortcut has an equivalent control
|
||||||
* key, meta key, or both. */
|
* key, an equivalent primary meta key sequence, or both. */
|
||||||
if (slen > 0) {
|
if (slen > 0) {
|
||||||
if (s->ctrlval != NANO_NO_KEY) {
|
if (s->ctrlval != NANO_NO_KEY) {
|
||||||
*meta_key = FALSE;
|
*meta_key = FALSE;
|
||||||
|
@ -1396,7 +1407,7 @@ const toggle *get_toggle(int kbinput, bool meta_key)
|
||||||
}
|
}
|
||||||
#endif /* !NANO_SMALL */
|
#endif /* !NANO_SMALL */
|
||||||
|
|
||||||
int get_edit_input(bool *meta_key, bool allow_funcs)
|
int get_edit_input(bool *meta_key, bool *func_key, bool allow_funcs)
|
||||||
{
|
{
|
||||||
bool keyhandled = FALSE;
|
bool keyhandled = FALSE;
|
||||||
int kbinput, retval;
|
int kbinput, retval;
|
||||||
|
@ -1405,7 +1416,7 @@ int get_edit_input(bool *meta_key, bool allow_funcs)
|
||||||
const toggle *t;
|
const toggle *t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
kbinput = get_kbinput(edit, meta_key);
|
kbinput = get_kbinput(edit, meta_key, func_key);
|
||||||
|
|
||||||
/* Universal shortcuts. These aren't in any shortcut lists, but we
|
/* Universal shortcuts. These aren't in any shortcut lists, but we
|
||||||
* should handle them anyway. */
|
* should handle them anyway. */
|
||||||
|
@ -1425,7 +1436,7 @@ int get_edit_input(bool *meta_key, bool allow_funcs)
|
||||||
#ifndef DISABLE_MOUSE
|
#ifndef DISABLE_MOUSE
|
||||||
case KEY_MOUSE:
|
case KEY_MOUSE:
|
||||||
if (get_edit_mouse()) {
|
if (get_edit_mouse()) {
|
||||||
kbinput = get_kbinput(edit, meta_key);
|
kbinput = get_kbinput(edit, meta_key, func_key);
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
return ERR;
|
return ERR;
|
||||||
|
@ -1433,7 +1444,7 @@ int get_edit_input(bool *meta_key, bool allow_funcs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check for a shortcut in the main list. */
|
/* Check for a shortcut in the main list. */
|
||||||
s = get_shortcut(main_list, kbinput, meta_key);
|
s = get_shortcut(main_list, kbinput, meta_key, func_key);
|
||||||
|
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
/* We got a shortcut. Run the shortcut's corresponding function
|
/* We got a shortcut. Run the shortcut's corresponding function
|
||||||
|
@ -1755,7 +1766,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
int kbinput;
|
int kbinput;
|
||||||
bool meta_key;
|
bool meta_key, func_key;
|
||||||
static int x = -1;
|
static int x = -1;
|
||||||
/* the cursor position in 'answer' */
|
/* the cursor position in 'answer' */
|
||||||
int xend;
|
int xend;
|
||||||
|
@ -1812,7 +1823,8 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
|
||||||
* to files not specified on the command line. In this case,
|
* to files not specified on the command line. In this case,
|
||||||
* disable all keys that would change the text if the filename isn't
|
* disable all keys that would change the text if the filename isn't
|
||||||
* blank and we're at the "Write File" prompt. */
|
* blank and we're at the "Write File" prompt. */
|
||||||
while ((kbinput = get_kbinput(bottomwin, &meta_key)) != NANO_ENTER_KEY) {
|
while ((kbinput = get_kbinput(bottomwin, &meta_key, &func_key)) !=
|
||||||
|
NANO_ENTER_KEY) {
|
||||||
for (t = s; t != NULL; t = t->next) {
|
for (t = s; t != NULL; t = t->next) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput);
|
fprintf(stderr, "Aha! \'%c\' (%d)\n", kbinput, kbinput);
|
||||||
|
@ -3112,12 +3124,12 @@ int do_yesno(int all, const char *msg)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int kbinput;
|
int kbinput;
|
||||||
bool meta_key;
|
bool meta_key, func_key;
|
||||||
#ifndef DISABLE_MOUSE
|
#ifndef DISABLE_MOUSE
|
||||||
int mouse_x, mouse_y;
|
int mouse_x, mouse_y;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
kbinput = get_kbinput(edit, &meta_key);
|
kbinput = get_kbinput(edit, &meta_key, &func_key);
|
||||||
|
|
||||||
if (kbinput == NANO_CANCEL_KEY)
|
if (kbinput == NANO_CANCEL_KEY)
|
||||||
ok = -1;
|
ok = -1;
|
||||||
|
@ -3281,7 +3293,7 @@ void do_help(void)
|
||||||
/* no_more means the end of the help text is shown, so don't go
|
/* no_more means the end of the help text is shown, so don't go
|
||||||
* down any more. */
|
* down any more. */
|
||||||
int kbinput = ERR;
|
int kbinput = ERR;
|
||||||
bool meta_key;
|
bool meta_key, func_key;
|
||||||
|
|
||||||
bool old_no_help = ISSET(NO_HELP);
|
bool old_no_help = ISSET(NO_HELP);
|
||||||
#ifndef DISABLE_MOUSE
|
#ifndef DISABLE_MOUSE
|
||||||
|
@ -3377,7 +3389,7 @@ void do_help(void)
|
||||||
no_more = (*ptr == '\0');
|
no_more = (*ptr == '\0');
|
||||||
|
|
||||||
skip_redisplay:
|
skip_redisplay:
|
||||||
kbinput = get_kbinput(edit, &meta_key);
|
kbinput = get_kbinput(edit, &meta_key, &func_key);
|
||||||
} while (kbinput != NANO_CANCEL_KEY && kbinput != NANO_EXIT_KEY &&
|
} while (kbinput != NANO_CANCEL_KEY && kbinput != NANO_EXIT_KEY &&
|
||||||
kbinput != NANO_EXIT_FKEY);
|
kbinput != NANO_EXIT_FKEY);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue