From c2c5a51e5238cc5ab9419667db3bb15d565c519c Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Fri, 23 Jan 2004 19:26:17 +0000 Subject: [PATCH] add support for escape sequences for F1-F14 where conflicts don't occur (and resurrect abcd() to make that job easier), additional comments, and a few minor cosmetic cleanups git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1632 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 12 ++ src/files.c | 4 +- src/global.c | 22 +-- src/nano.h | 4 +- src/proto.h | 1 + src/winio.c | 386 ++++++++++++++++++++++++++++++++++++++------------- 6 files changed, 314 insertions(+), 115 deletions(-) diff --git a/ChangeLog b/ChangeLog index e18a6370..8bef8ac0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,11 @@ CVS code - window when color support is enabled (in order to properly handle multi-line color regexes) to only do so when it's necessary, i.e, when COLOR_SYNTAX is set. (DLR) + - Minor cosmetic tweaks to the code involving direction keys. + NANO_UP_KEY and NANO_DOWN_KEY are now NANO_PREVLINE_KEY and + NANO_NEXTLINE_KEY, and the help messages for them have been + changed accordingly. Also remove extraneous references to + NANO_DOWN_KEY in the search history shortcut entries. (DLR) - nano.c: main() - Move the call to raw() on systems that don't define @@ -17,6 +22,13 @@ CVS code - - winio.c: get_accepted_kbinput() - Don't use "kbinput = wgetch(win)" as a switch value. (DLR) + get_escape_seq_kbinput() + - Add support for the escape sequences for F1-F14 whenever + possible (i.e, whenever a conflict doesn't occur), some + additional comments, and a few cosmetic cleanups. (DLR) + get_escape_seq_abcd() + - A resurrected version of the old abcd() function, readded in + order to simplify get_escape_seq_kbinput(). (DLR) get_page_start() - For consistency, tweak so that scrolling always occurs when we try to move onto the "$" at the end of the line, as opposed to diff --git a/src/files.c b/src/files.c index 12e028df..5221f26f 100644 --- a/src/files.c +++ b/src/files.c @@ -2571,7 +2571,7 @@ char *do_browser(const char *inpath) break; #endif - case NANO_UP_KEY: + case NANO_PREVLINE_KEY: if (selected - width >= 0) selected -= width; break; @@ -2579,7 +2579,7 @@ char *do_browser(const char *inpath) if (selected > 0) selected--; break; - case NANO_DOWN_KEY: + case NANO_NEXTLINE_KEY: if (selected + width <= numents - 1) selected += width; break; diff --git a/src/global.c b/src/global.c index 6141e38a..91fdefd9 100644 --- a/src/global.c +++ b/src/global.c @@ -328,8 +328,8 @@ void shortcut_init(int unjustify) "", *nano_whereis_next_msg = "", *nano_prevpage_msg = "", *nano_nextpage_msg = "", *nano_cut_msg = "", *nano_uncut_msg = "", *nano_cursorpos_msg = - "", *nano_spell_msg = "", *nano_up_msg = - "", *nano_down_msg = "", *nano_forward_msg = + "", *nano_spell_msg = "", *nano_prevline_msg = + "", *nano_nextline_msg = "", *nano_forward_msg = "", *nano_back_msg = "", *nano_home_msg = "", *nano_end_msg = "", *nano_firstline_msg = "", *nano_lastline_msg = "", *nano_refresh_msg = @@ -374,8 +374,8 @@ void shortcut_init(int unjustify) nano_uncut_msg = _("Uncut from the cutbuffer into the current line"); nano_cursorpos_msg = _("Show the position of the cursor"); nano_spell_msg = _("Invoke the spell checker, if available"); - nano_up_msg = _("Move up one line"); - nano_down_msg = _("Move down one line"); + nano_prevline_msg = _("Move to the previous line"); + nano_nextline_msg = _("Move to the next line"); nano_forward_msg = _("Move forward one character"); nano_back_msg = _("Move back one character"); nano_home_msg = _("Move to the beginning of the current line"); @@ -520,12 +520,12 @@ void shortcut_init(int unjustify) IFHELP(nano_replace_msg, NANO_ALT_REPLACE_KEY), NANO_REPLACE_FKEY, NANO_NO_KEY, NOVIEW, do_replace); - sc_init_one(&main_list, NANO_UP_KEY, _("Up"), - IFHELP(nano_up_msg, NANO_NO_KEY), NANO_NO_KEY, + sc_init_one(&main_list, NANO_PREVLINE_KEY, _("Prev Line"), + IFHELP(nano_prevline_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, VIEW, do_up); - sc_init_one(&main_list, NANO_DOWN_KEY, _("Down"), - IFHELP(nano_down_msg, NANO_NO_KEY), NANO_NO_KEY, + sc_init_one(&main_list, NANO_NEXTLINE_KEY, _("Next Line"), + IFHELP(nano_nextline_msg, NANO_NO_KEY), NANO_NO_KEY, NANO_NO_KEY, VIEW, do_down); sc_init_one(&main_list, NANO_FORWARD_KEY, _("Forward"), @@ -716,7 +716,7 @@ void shortcut_init(int unjustify) sc_init_one(&replace_list, NANO_HISTORY_KEY, _("History"), IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY, - NANO_DOWN_KEY, VIEW, 0); + NANO_NO_KEY, VIEW, 0); #endif /* !NANO_SMALL */ free_shortcutage(&replace_list_2); @@ -738,9 +738,9 @@ void shortcut_init(int unjustify) NANO_NO_KEY, VIEW, do_last_line); #ifndef NANO_SMALL - sc_init_one(&replace_list_2, NANO_UP_KEY, _("History"), + sc_init_one(&replace_list_2, NANO_PREVLINE_KEY, _("History"), IFHELP(nano_editstr_msg, NANO_NO_KEY), NANO_NO_KEY, - NANO_DOWN_KEY, VIEW, 0); + NANO_NO_KEY, VIEW, 0); #endif free_shortcutage(&goto_list); diff --git a/src/nano.h b/src/nano.h index 440120f3..419d5bef 100644 --- a/src/nano.h +++ b/src/nano.h @@ -405,8 +405,8 @@ typedef struct historyheadtype { #define NANO_JUSTIFY_KEY NANO_CONTROL_J #define NANO_JUSTIFY_FKEY KEY_F(4) #define NANO_UNJUSTIFY_KEY NANO_CONTROL_U -#define NANO_UP_KEY NANO_CONTROL_P -#define NANO_DOWN_KEY NANO_CONTROL_N +#define NANO_PREVLINE_KEY NANO_CONTROL_P +#define NANO_NEXTLINE_KEY NANO_CONTROL_N #define NANO_FORWARD_KEY NANO_CONTROL_F #define NANO_BACK_KEY NANO_CONTROL_B #define NANO_MARK_KEY NANO_CONTROL_6 diff --git a/src/proto.h b/src/proto.h index 97ffc15c..12ae7928 100644 --- a/src/proto.h +++ b/src/proto.h @@ -443,6 +443,7 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta); int get_ascii_kbinput(WINDOW *win, int kbinput); int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int escape_seq_len); +int get_escape_seq_abcd(int kbinput); int get_mouseinput(int *mouse_x, int *mouse_y, int shortcut); int do_first_line(void); int do_last_line(void); diff --git a/src/winio.c b/src/winio.c index bf39103a..538309bc 100644 --- a/src/winio.c +++ b/src/winio.c @@ -36,8 +36,11 @@ static int statblank = 0; /* Number of keystrokes left after actually blank the statusbar */ /* Read in a single input character. If it's ignored, swallow it and go - * on. Otherwise, try to translate it from ASCII and extended (keypad) - * input. Assume nodelay(win) is FALSE. */ + * on. Otherwise, try to translate it from ASCII, extended keypad + * values, and/or escape sequences. Supported extended keypad values + * consist of [arrow key], Ctrl-[arrow key], Shift-[arrow key], Enter, + * Backspace, Insert, Delete, Home, End, PageUp, PageDown, and F1-F14. + * Assume nodelay(win) is FALSE. */ int get_kbinput(WINDOW *win, int *meta) { int kbinput, retval; @@ -48,7 +51,7 @@ int get_kbinput(WINDOW *win, int *meta) return retval; } -/* 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, and return the length of the string in kbinput_len. Assume * nodelay(win) is FALSE. */ char *get_verbatim_kbinput(WINDOW *win, int *kbinput_len, @@ -111,8 +114,9 @@ int get_ignored_kbinput(WINDOW *win) } } -/* Translate acceptable ASCII and extended (keypad) input. Set meta to - * 1 if we get a Meta sequence. Assume nodelay(win) is FALSE. */ +/* Translate acceptable ASCII, extended keypad values, and/or escape + * sequences. Set meta to 1 if we get a Meta sequence. Assume + * nodelay(win) is FALSE. */ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta) { *meta = 0; @@ -184,10 +188,10 @@ int get_accepted_kbinput(WINDOW *win, int kbinput, int *meta) kbinput = ISSET(REBIND_DELETE) ? NANO_DELETE_KEY : NANO_BACKSPACE_KEY; break; case KEY_DOWN: - kbinput = NANO_DOWN_KEY; + kbinput = NANO_NEXTLINE_KEY; break; case KEY_UP: - kbinput = NANO_UP_KEY; + kbinput = NANO_PREVLINE_KEY; break; case KEY_LEFT: kbinput = NANO_BACK_KEY; @@ -304,29 +308,58 @@ int get_ascii_kbinput(WINDOW *win, int kbinput) return retval; } -/* Translate common escape sequences for some keys. These are generated - * when the terminal doesn't support those keys. Assume that Escape has - * already been read in, and that nodelay(win) is TRUE. */ +/* Translate escape sequences for extended keypad values. These are + * generated when the terminal doesn't support the needed keys. Assume + * that Escape has already been read in, and that nodelay(win) is TRUE. + * + * The supported terminals are the Linux console, the FreeBSD console, + * the Hurd console (a.k.a. the Mach console), xterm, rxvt, and Eterm. + * There are several escape sequence conflicts and omissions, outlined + * as follows: + * + * - F1 on FreeBSD console == kmous on xterm/rxvt/Eterm; the latter is + * omitted. (Mouse input will only work properly if the extended + * keypad value KEY_MOUSE is generated on mouse events instead of the + * kmous escape sequence.) + * - F9 on FreeBSD console == PageDown on Hurd console; the former is + * omitted. (The PC keypad, consisting of Insert, Delete, Home, End, + * PageUp, and PageDown, is more important to have working than the + * function keys, because the functions of the former are not + * arbitrary and the functions of the latter are.) + * - F10 on FreeBSD console == PageUp on Hurd console; the former is + * omitted. (Same as above.) + * - F13 on FreeBSD console == End on Hurd console; the former is + * omitted. (Same as above.) + * - The Hurd console has no escape sequences for F11, F12, F13, or + * F14. */ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int escape_seq_len) { - int kbinput = -1; + int kbinput = ERR; if (escape_seq_len > 1) { switch (escape_seq[0]) { case 'O': switch (escape_seq[1]) { - case 'A': /* Esc O A == Up on xterm. */ - kbinput = NANO_UP_KEY; + case '2': + if (escape_seq_len >= 3) { + switch (escape_seq[2]) { + case 'P': /* Esc O 2 P == F13 on + * xterm. */ + kbinput = KEY_F(13); + break; + case 'Q': /* Esc O 2 Q == F14 on + * xterm. */ + kbinput = KEY_F(14); + break; + } + } break; + case 'A': /* Esc O A == Up on xterm. */ case 'B': /* Esc O B == Down on xterm. */ - kbinput = NANO_DOWN_KEY; - break; case 'C': /* Esc O C == Right on xterm. */ - kbinput = NANO_FORWARD_KEY; - break; case 'D': /* Esc O D == Left on xterm. */ - kbinput = NANO_BACK_KEY; + kbinput = get_escape_seq_abcd(escape_seq[1]); break; case 'F': /* Esc O F == End on xterm. */ kbinput = NANO_END_KEY; @@ -334,33 +367,51 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int case 'H': /* Esc O H == Home on xterm. */ kbinput = NANO_HOME_KEY; break; - case 'a': /* Esc O a == Ctrl-Up on rxvt. */ - kbinput = NANO_UP_KEY; + case 'P': /* Esc O P == F1 on Hurd console. */ + kbinput = KEY_F(1); break; - case 'b': /* Esc O b == Ctrl-Down on rxvt. */ - kbinput = NANO_DOWN_KEY; + case 'Q': /* Esc O Q == F2 on Hurd console. */ + kbinput = KEY_F(2); break; - case 'c': /* Esc O c == Ctrl-Right on rxvt. */ - kbinput = NANO_FORWARD_KEY; + case 'R': /* Esc O R == F3 on Hurd console. */ + kbinput = KEY_F(3); + break; + case 'S': /* Esc O S == F4 on Hurd console. */ + kbinput = KEY_F(4); + break; + case 'T': /* Esc O T == F5 on Hurd console. */ + kbinput = KEY_F(5); + break; + case 'U': /* Esc O U == F6 on Hurd console. */ + kbinput = KEY_F(6); + break; + case 'V': /* Esc O V == F7 on Hurd console. */ + kbinput = KEY_F(7); + break; + case 'W': /* Esc O W == F8 on Hurd console. */ + kbinput = KEY_F(8); break; + case 'X': /* Esc O X == F9 on Hurd console. */ + kbinput = KEY_F(9); + break; + case 'Y': /* Esc O Y == F10 on Hurd console. */ + kbinput = KEY_F(10); + break; + case 'a': /* Esc O a == Ctrl-Up on rxvt. */ + case 'b': /* Esc O b == Ctrl-Down on rxvt. */ + case 'c': /* Esc O c == Ctrl-Right on rxvt. */ case 'd': /* Esc O d == Ctrl-Left on rxvt. */ - kbinput = NANO_BACK_KEY; + kbinput = get_escape_seq_abcd(escape_seq[1]); break; } break; case 'o': switch (escape_seq[1]) { case 'a': /* Esc o a == Ctrl-Up on Eterm. */ - kbinput = NANO_UP_KEY; - break; case 'b': /* Esc o b == Ctrl-Down on Eterm. */ - kbinput = NANO_DOWN_KEY; - break; case 'c': /* Esc o c == Ctrl-Right on Eterm. */ - kbinput = NANO_FORWARD_KEY; - break; case 'd': /* Esc o d == Ctrl-Left on Eterm. */ - kbinput = NANO_BACK_KEY; + kbinput = get_escape_seq_abcd(escape_seq[1]); break; } break; @@ -368,62 +419,108 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int switch (escape_seq[1]) { case '1': if (escape_seq_len >= 5) { - if (!strncmp(escape_seq, "[1;2", 4)) { + if (!strncmp(escape_seq + 2, ";2", 2)) { switch (escape_seq[4]) { - case 'A': - /* Esc [ 1 ; 2 A == Shift-Up on - * xterm. */ - kbinput = NANO_UP_KEY; - break; - case 'B': - /* Esc [ 1 ; 2 B == Shift-Down - * on xterm. */ - kbinput = NANO_DOWN_KEY; - break; - case 'C': - /* Esc [ 1 ; 2 C == Shift-Right - * on xterm. */ - kbinput = NANO_FORWARD_KEY; - break; - case 'D': - /* Esc [ 1 ; 2 D == Shift-Left - * on xterm. */ - kbinput = NANO_BACK_KEY; + case 'A': /* Esc [ 1 ; 2 A == + * Shift-Up on xterm. */ + case 'B': /* Esc [ 1 ; 2 B == + * Shift-Down on xterm. */ + case 'C': /* Esc [ 1 ; 2 C == + * Shift-Right on + * xterm. */ + case 'D': /* Esc [ 1 ; 2 D == + * Shift-Left on xterm. */ + kbinput = get_escape_seq_abcd(escape_seq[1]); break; } - } else if (!strncmp(escape_seq, "[1;5", 4)) { + } else if (!strncmp(escape_seq + 2, ";5", 2)) { switch (escape_seq[4]) { - case 'A': - /* Esc [ 1 ; 5 A == Ctrl-Up on - * xterm. */ - kbinput = NANO_UP_KEY; - break; - case 'B': - /* Esc [ 1 ; 5 B == Ctrl-Down on - * xterm. */ - kbinput = NANO_DOWN_KEY; - break; - case 'C': - /* Esc [ 1 ; 5 C == Ctrl-Right - * on xterm. */ - kbinput = NANO_FORWARD_KEY; - break; - case 'D': - /* Esc [ 1 ; 5 D == Ctrl-Left on - * xterm. */ - kbinput = NANO_BACK_KEY; + case 'A': /* Esc [ 1 ; 5 A == + * Ctrl-Up on xterm. */ + case 'B': /* Esc [ 1 ; 5 B == + * Ctrl-Down on xterm. */ + case 'C': /* Esc [ 1 ; 5 C == + * Ctrl-Right on xterm. */ + case 'D': /* Esc [ 1 ; 5 D == + * Ctrl-Left on xterm. */ + kbinput = get_escape_seq_abcd(escape_seq[1]); break; } } - break; - } else { - /* Esc [ 1 ~ == Home on Linux console. */ - kbinput = NANO_HOME_KEY; - break; + } else if (escape_seq_len >= 3) { + switch (escape_seq[2]) { + case '1': /* Esc [ 1 1 ~ == F1 on + * rxvt/Eterm. */ + kbinput = KEY_F(1); + break; + case '2': /* Esc [ 1 2 ~ == F2 on + * rxvt/Eterm. */ + kbinput = KEY_F(2); + break; + case '3': /* Esc [ 1 3 ~ == F3 on + * rxvt/Eterm. */ + kbinput = KEY_F(3); + break; + case '4': /* Esc [ 1 4 ~ == F4 on + * rxvt/Eterm. */ + kbinput = KEY_F(4); + break; + case '5': /* Esc [ 1 5 ~ == F5 on + * xterm/rxvt/Eterm. */ + kbinput = KEY_F(5); + break; + case '7': /* Esc [ 1 7 ~ == F6 on Linux + * console/xterm/rxvt/Eterm. */ + kbinput = KEY_F(6); + break; + case '8': /* Esc [ 1 8 ~ == F7 on Linux + * console/xterm/rxvt/Eterm. */ + kbinput = KEY_F(7); + break; + case '9': /* Esc [ 1 9 ~ == F8 on Linux + * console/xterm/rxvt/Eterm. */ + kbinput = KEY_F(8); + break; + default: /* Esc [ 1 ~ == Home on Linux + * console. */ + kbinput = NANO_HOME_KEY; + break; + } + } + break; + case '2': + if (escape_seq_len >= 3) { + switch (escape_seq[2]) { + case '0': /* Esc [ 2 0 ~ == F9 on Linux + * console/xterm/rxvt/Eterm. */ + kbinput = KEY_F(9); + break; + case '1': /* Esc [ 2 1 ~ == F10 on Linux + * console/xterm/rxvt/Eterm. */ + kbinput = KEY_F(10); + break; + case '3': /* Esc [ 2 3 ~ == F11 on Linux + * console/xterm/rxvt/Eterm. */ + kbinput = KEY_F(11); + break; + case '4': /* Esc [ 2 4 ~ == F12 on Linux + * console/xterm/rxvt/Eterm. */ + kbinput = KEY_F(12); + break; + case '5': /* Esc [ 2 5 ~ == F13 on Linux + * console/rxvt/Eterm. */ + kbinput = KEY_F(13); + break; + case '6': /* Esc [ 2 6 ~ == F14 on Linux + * console/rxvt/Eterm. */ + kbinput = KEY_F(14); + break; + default: /* Esc [ 2 ~ == Insert on Linux + * console/xterm. */ + kbinput = NANO_INSERTFILE_KEY; + break; + } } - case '2': /* Esc [ 2 ~ == Insert on Linux - * console/xterm. */ - kbinput = NANO_INSERTFILE_KEY; break; case '3': /* Esc [ 3 ~ == Delete on Linux * console/xterm. */ @@ -434,12 +531,12 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int kbinput = NANO_END_KEY; break; case '5': /* Esc [ 5 ~ == PageUp on Linux - * console/xterm, Esc [ 5 ^ == PageUp on + * console/xterm; Esc [ 5 ^ == PageUp on * Eterm. */ kbinput = NANO_PREVPAGE_KEY; break; case '6': /* Esc [ 6 ~ == PageDown on Linux - * console/xterm, Esc [ 6 ^ == PageDown on + * console/xterm; Esc [ 6 ^ == PageDown on * Eterm. */ kbinput = NANO_NEXTPAGE_KEY; break; @@ -457,22 +554,16 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int break; case 'A': /* Esc [ A == Up on Linux console/FreeBSD * console/Hurd console/rxvt/Eterm. */ - kbinput = NANO_UP_KEY; - break; case 'B': /* Esc [ B == Down on Linux * console/FreeBSD console/Hurd * console/rxvt/Eterm. */ - kbinput = NANO_DOWN_KEY; - break; case 'C': /* Esc [ C == Right on Linux * console/FreeBSD console/Hurd * console/rxvt/Eterm. */ - kbinput = NANO_FORWARD_KEY; - break; case 'D': /* Esc [ D == Left on Linux * console/FreeBSD console/Hurd * console/rxvt/Eterm. */ - kbinput = NANO_BACK_KEY; + kbinput = get_escape_seq_abcd(escape_seq[1]); break; case 'F': /* Esc [ F == End on FreeBSD * console/Eterm. */ @@ -494,34 +585,110 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int * console. */ kbinput = NANO_INSERTFILE_KEY; break; + case 'M': /* Esc [ M == F1 on FreeBSD console. */ + kbinput = KEY_F(1); + break; + case 'N': /* Esc [ N == F2 on FreeBSD console. */ + kbinput = KEY_F(2); + break; + case 'O': + if (escape_seq_len >= 3) { + switch (escape_seq[2]) { + case 'P': /* Esc [ O P == F1 on + * xterm. */ + kbinput = KEY_F(1); + break; + case 'Q': /* Esc [ O Q == F2 on + * xterm. */ + kbinput = KEY_F(2); + break; + case 'R': /* Esc [ O R == F3 on + * xterm. */ + kbinput = KEY_F(3); + break; + case 'S': /* Esc [ O S == F4 on + * xterm. */ + kbinput = KEY_F(4); + break; + default: /* Esc [ O == F3 on + * FreeBSD console. */ + kbinput = KEY_F(3); + break; + } + } + break; + case 'P': /* Esc [ P == F4 on FreeBSD console. */ + kbinput = KEY_F(4); + break; + case 'Q': /* Esc [ Q == F5 on FreeBSD console. */ + kbinput = KEY_F(5); + break; + case 'R': /* Esc [ R == F6 on FreeBSD console. */ + kbinput = KEY_F(6); + break; + case 'S': /* Esc [ S == F7 on FreeBSD console. */ + kbinput = KEY_F(7); + break; + case 'T': /* Esc [ T == F8 on FreeBSD console. */ + kbinput = KEY_F(8); + break; case 'U': /* Esc [ U == PageDown on Hurd console. */ kbinput = NANO_NEXTPAGE_KEY; break; case 'V': /* Esc [ V == PageUp on Hurd console. */ kbinput = NANO_PREVPAGE_KEY; break; + case 'W': /* Esc [ W == F11 on FreeBSD console. */ + kbinput = KEY_F(11); + break; + case 'X': /* Esc [ X == F12 on FreeBSD console. */ + kbinput = KEY_F(12); + break; case 'Y': /* Esc [ Y == End on Hurd console. */ kbinput = NANO_END_KEY; break; - case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */ - kbinput = NANO_UP_KEY; + case 'Z': /* Esc [ Z == F14 on FreeBSD console. */ + kbinput = KEY_F(14); break; + case 'a': /* Esc [ a == Shift-Up on rxvt/Eterm. */ case 'b': /* Esc [ b == Shift-Down on rxvt/Eterm. */ - kbinput = NANO_DOWN_KEY; - break; case 'c': /* Esc [ c == Shift-Right on * rxvt/Eterm. */ - kbinput = NANO_FORWARD_KEY; - break; case 'd': /* Esc [ d == Shift-Left on rxvt/Eterm. */ - kbinput = NANO_BACK_KEY; + kbinput = get_escape_seq_abcd(escape_seq[1]); + break; + case '[': + if (escape_seq_len >= 3) { + switch (escape_seq[2]) { + case 'A': /* Esc [ [ A == F1 on Linux + * console. */ + kbinput = KEY_F(1); + break; + case 'B': /* Esc [ [ B == F2 on Linux + * console. */ + kbinput = KEY_F(2); + break; + case 'C': /* Esc [ [ C == F3 on Linux + * console. */ + kbinput = KEY_F(3); + break; + case 'D': /* Esc [ [ D == F4 on Linux + * console. */ + kbinput = KEY_F(4); + break; + case 'E': /* Esc [ [ E == F5 on Linux + * console. */ + kbinput = KEY_F(5); + break; + } + } break; } break; } } - if (kbinput == -1) { + if (kbinput == ERR) { /* This escape sequence is unrecognized; send it back. */ for (; escape_seq_len > 1; escape_seq_len--) ungetch(escape_seq[escape_seq_len - 1]); @@ -531,6 +698,25 @@ int get_escape_seq_kbinput(WINDOW *win, char *escape_seq, int return kbinput; } +/* Return the equivalent arrow key value for the case-insensitive + * letters A (up), B (down), C (left), and D (right). These are common + * to many escape sequences. */ +int get_escape_seq_abcd(int kbinput) +{ + switch (tolower(kbinput)) { + case 'a': + return NANO_PREVLINE_KEY; + case 'b': + return NANO_NEXTLINE_KEY; + case 'c': + return NANO_FORWARD_KEY; + case 'd': + return NANO_BACK_KEY; + default: + return ERR; + } +} + #ifndef DISABLE_MOUSE /* Check for a mouse event, and if one's taken place, save the * coordinates where it took place in mouse_x and mouse_y. After that, @@ -916,7 +1102,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, #endif #ifndef NANO_SMALL /* Have to handle these here too, for the time being */ - if (kbinput == NANO_UP_KEY || kbinput == NANO_DOWN_KEY) + if (kbinput == NANO_PREVLINE_KEY || kbinput == NANO_NEXTLINE_KEY) break; #endif @@ -999,7 +1185,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, if (x > 0) x--; break; - case NANO_UP_KEY: + case NANO_PREVLINE_KEY: #ifndef NANO_SMALL if (history_list != NULL) { @@ -1041,7 +1227,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def, } #endif break; - case NANO_DOWN_KEY: + case NANO_NEXTLINE_KEY: #ifndef NANO_SMALL if (history_list != NULL) { -- 2.39.5