From 8f4d17e8352881c686488f61bf48969461f1e662 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Sat, 1 Feb 2014 13:46:30 +1000 Subject: Rename some keys and remove special casing of MC Esc digit sequences. --- boxes.c | 55 +++++++++++++++++++++++++++++++------------------------ dumbsh.c | 3 +-- handlekeys.c | 35 +++++------------------------------ handlekeys.h | 3 +-- 4 files changed, 38 insertions(+), 58 deletions(-) diff --git a/boxes.c b/boxes.c index 0923cab..c2bc226 100644 --- a/boxes.c +++ b/boxes.c @@ -1737,9 +1737,10 @@ struct keyCommand simpleCommandKeys[] = {"F10", "quit"}, {"Home", "startOfLine"}, {"Left", "leftChar"}, + {"Enter", "executeLine"}, {"Return", "executeLine"}, {"Right", "rightChar"}, - {"^[", "switchMode"}, + {"Esc", "switchMode"}, {"Up", "upLine"}, {NULL, NULL} }; @@ -1782,6 +1783,7 @@ struct function simpleEmacsCommands[] = // The key to command mappings. struct keyCommand simpleEmacsKeys[] = { + {"BS", "delete-backward-char"}, {"Del", "delete-backward-char"}, {"^D", "delete-char"}, {"Down", "next-line"}, @@ -1797,15 +1799,15 @@ struct keyCommand simpleEmacsKeys[] = {"PgDn", "scroll-up"}, {"^V", "scroll-up"}, {"PgUp", "scroll-down"}, - {"^[v", "scroll-down"}, // M-v + {"Escv", "scroll-down"}, // M-v + {"Enter", "newline"}, {"Return", "newline"}, {"Right", "forward-char"}, {"^F", "forward-char"}, - {"^[x", "execute-extended-command"}, // M-x + {"Escx", "execute-extended-command"}, // M-x {"^X2", "split-window-vertically"}, {"^X3", "split-window-horizontally"}, // TODO - Just making this up for now. {"^XP", "other-window"}, - {"^XP", "other-window"}, {"^X0", "delete-window"}, {"Up", "previous-line"}, {"^P", "previous-line"}, @@ -1816,7 +1818,6 @@ struct keyCommand simpleEmacsCommandKeys[] = { {"Del", "delete-backwards-char"}, {"^D", "delete-char"}, - {"^D", "delete-char"}, {"Down", "next-line"}, {"^N", "next-line"}, {"End", "end-of-line"}, @@ -1827,8 +1828,9 @@ struct keyCommand simpleEmacsCommandKeys[] = {"^B", "backward-char"}, {"Up", "previous-line"}, {"^P", "previous-line"}, + {"Enter", "accept-line"}, {"Return", "accept-line"}, - {"^[x", "execute-extended-command"}, + {"Escx", "execute-extended-command"}, {NULL, NULL} }; @@ -1901,11 +1903,12 @@ struct keyCommand simpleJoeKeys[] = {"^B", "ltarw"}, {"^V", "pgdn"}, // Actually half a page. {"^U", "pgup"}, // Actually half a page. + {"Enter", "open"}, {"Return", "open"}, {"Right", "rtarw"}, {"^F", "rtarw"}, - {"^[x", "execmd"}, - {"^[^X", "execmd"}, + {"Escx", "execmd"}, + {"Esc^X", "execmd"}, {"^Ko", "splitw"}, {"^K^O", "splitw"}, {"^Kn", "nextw"}, @@ -1929,10 +1932,11 @@ struct keyCommand simpleJoeCommandKeys[] = {"^B", "ltarw"}, {"Right", "rtarw"}, {"^F", "rtarw"}, - {"^[x", "execmd"}, - {"^[^X", "execmd"}, + {"Escx", "execmd"}, + {"Esc^X", "execmd"}, {"Up", "uparw"}, {"^P", "uparw"}, + {"Enter", "executeLine"}, {"Return", "executeLine"}, {NULL, NULL} }; @@ -1959,19 +1963,17 @@ struct context simpleJoe = // No cursor movement, just scrolling. // TODO - Put content into read only mode. // TODO - actually implement read only mode where up and down one line do actual scrolling instead of cursor movement. -// TODO - maybe I can support the ZZ command in one of two ways - -// Just have a Z command do the quit. -// Have the first Z go into a special mode, where anything other than a Z restores the original mode. struct keyCommand simpleLessKeys[] = { {"Down", "downLine"}, {"j", "downLine"}, + {"Enter", "downLine"}, {"Return", "downLine"}, {"End", "endOfLine"}, {"q", "quit"}, {":q", "quit"}, // TODO - A vi ism, should do ex command stuff instead. - {"ZZ", "quit"}, // The infrastructure here does not support this style of command. + {"ZZ", "quit"}, {"PgDn", "downPage"}, {"f", "downPage"}, {" ", "downPage"}, @@ -2005,10 +2007,11 @@ struct context simpleLess = struct keyCommand simpleMoreKeys[] = { {"j", "downLine"}, + {"Enter", "downLine"}, {"Return", "downLine"}, {"q", "quit"}, {":q", "quit"}, // See comments for "less". - {"ZZ", "quit"}, // See comments for "less". + {"ZZ", "quit"}, {"f", "downPage"}, {" ", "downPage"}, {"^F", "downPage"}, @@ -2044,21 +2047,22 @@ struct keyCommand simpleMceditKeys[] = {"Down", "downLine"}, {"End", "endOfLine"}, {"F10", "quit"}, - {"^[0", "quit"}, + {"Esc0", "quit"}, {"F2", "save"}, - {"^[2", "save"}, + {"Esc2", "save"}, {"Home", "startOfLine"}, {"Left", "leftChar"}, {"PgDn", "downPage"}, {"PgUp", "upPage"}, + {"Enter", "splitLine"}, {"Return", "splitLine"}, {"Right", "rightChar"}, {"Shift F2", "switchMode"}, // MC doesn't have a command mode. - {"^[:", "switchMode"}, // Sorta vi like, and coz tmux is screwing with the shift function keys somehow. - {"^[|", "splitV"}, // MC doesn't have a split window concept, so make these up to match tmux more or less. - {"^[-", "splitH"}, - {"^[o", "switchBoxes"}, - {"^[x", "deleteBox"}, + {"Esc:", "switchMode"}, // Sorta vi like, and coz tmux is screwing with the shift function keys somehow. + {"Esc|", "splitV"}, // MC doesn't have a split window concept, so make these up to match tmux more or less. + {"Esc-", "splitH"}, + {"Esco", "switchBoxes"}, + {"Escx", "deleteBox"}, {"Up", "upLine"}, {NULL, NULL} }; @@ -2128,6 +2132,7 @@ struct keyCommand simpleNanoKeys[] = {"PgDn", "downPage"}, {"^Y", "upPage"}, // ? {"PgUp", "upPage"}, + {"Enter", "enter"}, // TODO - Not sure if this is correct. {"Return", "enter"}, // TODO - Not sure if this is correct. {"^F", "right"}, {"Right", "right"}, @@ -2264,6 +2269,7 @@ struct keyCommand simpleViNormalKeys[] = {"^F", "downPage"}, {"PgUp", "upPage"}, {"^B", "upPage"}, + {"Enter", "startOfNextLine"}, {"Return", "startOfNextLine"}, {"Right", "rightChar"}, {"l", "rightChar"}, @@ -2289,7 +2295,7 @@ struct keyCommand simpleViInsertKeys[] = {"BS", "backSpaceChar"}, {"Del", "deleteChar"}, {"Return", "splitLine"}, - {"^[", "visual"}, + {"Esc", "visual"}, {"^C", "visual"}, {NULL, NULL} }; @@ -2302,9 +2308,10 @@ struct keyCommand simpleExKeys[] = {"End", "endOfLine"}, {"Home", "startOfLine"}, {"Left", "leftChar"}, + {"Enter", "executeLine"}, {"Return", "executeLine"}, {"Right", "rightChar"}, - {"^[", "visual"}, + {"Esc", "visual"}, {"Up", "upLine"}, {NULL, NULL} }; diff --git a/dumbsh.c b/dumbsh.c index a282caf..875614b 100644 --- a/dumbsh.c +++ b/dumbsh.c @@ -170,8 +170,7 @@ static struct keyCommand simpleEmacsKeys[] = {"Del", deleteChar}, {"^D", deleteChar}, {"Return", doCommand}, - {"^J", doCommand}, - {"^M", doCommand}, + {"Enter", doCommand}, {"Down", nextHistory}, {"^N", nextHistory}, {"End", endOfLine}, diff --git a/handlekeys.c b/handlekeys.c index 322d41e..030c933 100644 --- a/handlekeys.c +++ b/handlekeys.c @@ -18,8 +18,7 @@ struct key char *name; }; -// This table includes some variations I have found on some terminals, -// and the MC "Esc digit" versions. +// This table includes some variations I have found on some terminals. // http://rtfm.etla.org/xterm/ctlseq.html has a useful guide. // TODO - Don't think I got all the linux console variations. // TODO - Add more shift variations, plus Ctrl & Alt variations when needed. @@ -44,10 +43,10 @@ static struct key keys[] = {"\x07", "^G"}, // BEL {"\x08", "Del"}, // BS Delete key, usually. {"\x09", "Tab"}, // HT - {"\x0A", "Return"}, // LF Roxterm translates Ctrl-M to this. + {"\x0A", "Enter"}, // LF Roxterm translates Ctrl-M to this. {"\x0B", "^K"}, // VT {"\x0C", "^L"}, // FF - {"\x0D", "^M"}, // CR Other Return key, usually. + {"\x0D", "Return"}, // CR Other Enter/Return key, usually. {"\x0E", "^N"}, // SO {"\x0F", "^O"}, // SI DISCARD {"\x10", "^P"}, // DLE @@ -63,7 +62,7 @@ static struct key keys[] = {"\x1A", "^Z"}, // SUB SIGTSTP // Commented out coz it's the ANSI start byte in the below multibyte keys. // Handled in the code with a timeout. - //{"\x1B", "^["}, // ESC Esc key. + //{"\x1B", "Esc"}, // ESC Esc key. {"\x1C", "^\\"}, // FS SIGQUIT {"\x1D", "^]"}, // GS {"\x1E", "^^"}, // RS @@ -167,25 +166,6 @@ static struct key keys[] = {"\x1BO1;2Q", "Shift F2"}, {"\x1BO1;2R", "Shift F3"}, {"\x1BO1;2S", "Shift F4"}, - - // MC "Esc digit" specials. - // NOTE - The MC Esc variations might not be such a good idea, other programs - // want the Esc key for other things. - // Notably seems that "Esc somekey" is used in place of "Alt somekey" - // AKA "Meta somekey" coz apparently some OSes swallow those. - // Conversely, some terminals send "Esc somekey" when you do - // "Alt somekey". - // MC Esc variants might be used on Macs for other things? - {"\x1B\x31", "F1"}, - {"\x1B\x32", "F2"}, - {"\x1B\x33", "F3"}, - {"\x1B\x34", "F4"}, - {"\x1B\x35", "F5"}, - {"\x1B\x36", "F6"}, - {"\x1B\x37", "F7"}, - {"\x1B\x38", "F8"}, - {"\x1B\x39", "F9"}, - {"\x1B\x30", "F10"} }; static volatile sig_atomic_t sigWinch; @@ -196,9 +176,6 @@ static void handleSIGWINCH(int signalNumber) sigWinch = 1; } -// TODO - Unhandled complications - -// Less and more have the "ZZ" command, but nothing else seems to have -// multi ordinary character commands. void handle_keys(long extra, int (*handle_sequence)(long extra, char *sequence), void (*handle_CSI)(long extra, char *command, int *params, int count)) @@ -268,9 +245,7 @@ void handle_keys(long extra, { // After a short delay to check, this is a real Escape key, // not part of an escape sequence, so deal with it. - // TODO - So far the only uses of this have the escape at the start, - // but maybe a strcat is needed instead later? - strcpy(sequence, "^["); + strcat(sequence, "Esc"); buffer[0] = buffIndex = 0; } // TODO - Call some sort of timer tick callback. This wont be diff --git a/handlekeys.h b/handlekeys.h index 00e6e93..192d96c 100644 --- a/handlekeys.h +++ b/handlekeys.h @@ -9,8 +9,7 @@ * See the keys[] array at the top of handlekeys.c for what byte sequences get * translated into what key names. See dumbsh.c for an example of usage. * A 0.1 second delay is used to detect the Esc key being pressed, and not Esc - * being part of a raw keystroke. As a bonus, Midnight Commander style - * "Esc digit" sequences are translated to function keys. + * being part of a raw keystroke. * * handle_keys also tries to decode CSI commands that terminals can send. * Some keystrokes are CSI commands, but those are translated as key sequences -- cgit v1.1