aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--interactive-test.c86
-rw-r--r--libterminput.c107
-rw-r--r--libterminput.h7
3 files changed, 120 insertions, 80 deletions
diff --git a/interactive-test.c b/interactive-test.c
index d393a96..a1101e4 100644
--- a/interactive-test.c
+++ b/interactive-test.c
@@ -37,47 +37,51 @@ main(void)
case LIBTERMINPUT_SYMBOL:
printf("\t%s: %s\n", "key: symbol", input.keypress.symbol);
break;
- case LIBTERMINPUT_UP: printf("\t%s: %s\n", "key", "up"); break;
- case LIBTERMINPUT_DOWN: printf("\t%s: %s\n", "key", "down"); break;
- case LIBTERMINPUT_RIGHT: printf("\t%s: %s\n", "key", "right"); break;
- case LIBTERMINPUT_BEGIN: printf("\t%s: %s\n", "key", "begin"); break;
- case LIBTERMINPUT_PAUSE: printf("\t%s: %s\n", "key", "pause"); break;
- case LIBTERMINPUT_TAB: printf("\t%s: %s\n", "key", "tab"); break;
- case LIBTERMINPUT_F1: printf("\t%s: %s\n", "key", "f1"); break;
- case LIBTERMINPUT_F2: printf("\t%s: %s\n", "key", "f2"); break;
- case LIBTERMINPUT_F3: printf("\t%s: %s\n", "key", "f3"); break;
- case LIBTERMINPUT_F4: printf("\t%s: %s\n", "key", "f4"); break;
- case LIBTERMINPUT_F5: printf("\t%s: %s\n", "key", "f5"); break;
- case LIBTERMINPUT_F6: printf("\t%s: %s\n", "key", "f6"); break;
- case LIBTERMINPUT_F7: printf("\t%s: %s\n", "key", "f7"); break;
- case LIBTERMINPUT_F8: printf("\t%s: %s\n", "key", "f8"); break;
- case LIBTERMINPUT_F9: printf("\t%s: %s\n", "key", "f9"); break;
- case LIBTERMINPUT_F10: printf("\t%s: %s\n", "key", "f10"); break;
- case LIBTERMINPUT_F11: printf("\t%s: %s\n", "key", "f11"); break;
- case LIBTERMINPUT_F12: printf("\t%s: %s\n", "key", "f12"); break;
- case LIBTERMINPUT_HOME: printf("\t%s: %s\n", "key", "home"); break;
- case LIBTERMINPUT_INS: printf("\t%s: %s\n", "key", "ins"); break;
- case LIBTERMINPUT_DEL: printf("\t%s: %s\n", "key", "del"); break;
- case LIBTERMINPUT_END: printf("\t%s: %s\n", "key", "end"); break;
- case LIBTERMINPUT_PRIOR: printf("\t%s: %s\n", "key", "prior"); break;
- case LIBTERMINPUT_NEXT: printf("\t%s: %s\n", "key", "next"); break;
- case LIBTERMINPUT_ERASE: printf("\t%s: %s\n", "key", "erase"); break;
- case LIBTERMINPUT_ENTER: printf("\t%s: %s\n", "key", "enter"); break;
- case LIBTERMINPUT_ESC: printf("\t%s: %s\n", "key", "esc"); break;
- case LIBTERMINPUT_KEYPAD_0: printf("\t%s: %s\n", "key", "keypad 0"); break;
- case LIBTERMINPUT_KEYPAD_1: printf("\t%s: %s\n", "key", "keypad 1"); break;
- case LIBTERMINPUT_KEYPAD_2: printf("\t%s: %s\n", "key", "keypad 2"); break;
- case LIBTERMINPUT_KEYPAD_3: printf("\t%s: %s\n", "key", "keypad 3"); break;
- case LIBTERMINPUT_KEYPAD_4: printf("\t%s: %s\n", "key", "keypad 4"); break;
- case LIBTERMINPUT_KEYPAD_5: printf("\t%s: %s\n", "key", "keypad 5"); break;
- case LIBTERMINPUT_KEYPAD_6: printf("\t%s: %s\n", "key", "keypad 6"); break;
- case LIBTERMINPUT_KEYPAD_7: printf("\t%s: %s\n", "key", "keypad 7"); break;
- case LIBTERMINPUT_KEYPAD_8: printf("\t%s: %s\n", "key", "keypad 8"); break;
- case LIBTERMINPUT_KEYPAD_9: printf("\t%s: %s\n", "key", "keypad 9"); break;
- case LIBTERMINPUT_KEYPAD_MINUS: printf("\t%s: %s\n", "key", "keypad minus"); break;
- case LIBTERMINPUT_KEYPAD_COMMA: printf("\t%s: %s\n", "key", "keypad comma"); break;
- case LIBTERMINPUT_KEYPAD_POINT: printf("\t%s: %s\n", "key", "keypad point"); break;
- case LIBTERMINPUT_KEYPAD_ENTER: printf("\t%s: %s\n", "key", "keypad enter"); break;
+ case LIBTERMINPUT_UP: printf("\t%s: %s\n", "key", "up"); break;
+ case LIBTERMINPUT_DOWN: printf("\t%s: %s\n", "key", "down"); break;
+ case LIBTERMINPUT_RIGHT: printf("\t%s: %s\n", "key", "right"); break;
+ case LIBTERMINPUT_BEGIN: printf("\t%s: %s\n", "key", "begin"); break;
+ case LIBTERMINPUT_MACRO: printf("\t%s: %s\n", "key", "macro"); break;
+ case LIBTERMINPUT_TAB: printf("\t%s: %s\n", "key", "tab"); break;
+ case LIBTERMINPUT_F1: printf("\t%s: %s\n", "key", "f1"); break;
+ case LIBTERMINPUT_F2: printf("\t%s: %s\n", "key", "f2"); break;
+ case LIBTERMINPUT_F3: printf("\t%s: %s\n", "key", "f3"); break;
+ case LIBTERMINPUT_F4: printf("\t%s: %s\n", "key", "f4"); break;
+ case LIBTERMINPUT_F5: printf("\t%s: %s\n", "key", "f5"); break;
+ case LIBTERMINPUT_F6: printf("\t%s: %s\n", "key", "f6"); break;
+ case LIBTERMINPUT_F7: printf("\t%s: %s\n", "key", "f7"); break;
+ case LIBTERMINPUT_F8: printf("\t%s: %s\n", "key", "f8"); break;
+ case LIBTERMINPUT_F9: printf("\t%s: %s\n", "key", "f9"); break;
+ case LIBTERMINPUT_F10: printf("\t%s: %s\n", "key", "f10"); break;
+ case LIBTERMINPUT_F11: printf("\t%s: %s\n", "key", "f11"); break;
+ case LIBTERMINPUT_F12: printf("\t%s: %s\n", "key", "f12"); break;
+ case LIBTERMINPUT_HOME: printf("\t%s: %s\n", "key", "home"); break;
+ case LIBTERMINPUT_INS: printf("\t%s: %s\n", "key", "ins"); break;
+ case LIBTERMINPUT_DEL: printf("\t%s: %s\n", "key", "del"); break;
+ case LIBTERMINPUT_END: printf("\t%s: %s\n", "key", "end"); break;
+ case LIBTERMINPUT_PRIOR: printf("\t%s: %s\n", "key", "prior"); break;
+ case LIBTERMINPUT_NEXT: printf("\t%s: %s\n", "key", "next"); break;
+ case LIBTERMINPUT_ERASE: printf("\t%s: %s\n", "key", "erase"); break;
+ case LIBTERMINPUT_ENTER: printf("\t%s: %s\n", "key", "enter"); break;
+ case LIBTERMINPUT_ESC: printf("\t%s: %s\n", "key", "esc"); break;
+ case LIBTERMINPUT_KEYPAD_0: printf("\t%s: %s\n", "key", "keypad 0"); break;
+ case LIBTERMINPUT_KEYPAD_1: printf("\t%s: %s\n", "key", "keypad 1"); break;
+ case LIBTERMINPUT_KEYPAD_2: printf("\t%s: %s\n", "key", "keypad 2"); break;
+ case LIBTERMINPUT_KEYPAD_3: printf("\t%s: %s\n", "key", "keypad 3"); break;
+ case LIBTERMINPUT_KEYPAD_4: printf("\t%s: %s\n", "key", "keypad 4"); break;
+ case LIBTERMINPUT_KEYPAD_5: printf("\t%s: %s\n", "key", "keypad 5"); break;
+ case LIBTERMINPUT_KEYPAD_6: printf("\t%s: %s\n", "key", "keypad 6"); break;
+ case LIBTERMINPUT_KEYPAD_7: printf("\t%s: %s\n", "key", "keypad 7"); break;
+ case LIBTERMINPUT_KEYPAD_8: printf("\t%s: %s\n", "key", "keypad 8"); break;
+ case LIBTERMINPUT_KEYPAD_9: printf("\t%s: %s\n", "key", "keypad 9"); break;
+ case LIBTERMINPUT_KEYPAD_PLUS: printf("\t%s: %s\n", "key", "keypad plus"); break;
+ case LIBTERMINPUT_KEYPAD_MINUS: printf("\t%s: %s\n", "key", "keypad minus"); break;
+ case LIBTERMINPUT_KEYPAD_TIMES: printf("\t%s: %s\n", "key", "keypad times"); break;
+ case LIBTERMINPUT_KEYPAD_DIVISION: printf("\t%s: %s\n", "key", "keypad division"); break;
+ case LIBTERMINPUT_KEYPAD_DECIMAL: printf("\t%s: %s\n", "key", "keypad decimal"); break;
+ case LIBTERMINPUT_KEYPAD_COMMA: printf("\t%s: %s\n", "key", "keypad comma"); break;
+ case LIBTERMINPUT_KEYPAD_POINT: printf("\t%s: %s\n", "key", "keypad point"); break;
+ case LIBTERMINPUT_KEYPAD_ENTER: printf("\t%s: %s\n", "key", "keypad enter"); break;
default:
printf("\t%s: %s\n", "key", "other");
break;
diff --git a/libterminput.c b/libterminput.c
index 2ea9a18..8fb1fb6 100644
--- a/libterminput.c
+++ b/libterminput.c
@@ -175,7 +175,7 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx)
switch (keylen) {
case 2:
switch (ctx->key[1]) {
- case '@': input->keypress.key = LIBTERMINPUT_INS; break;
+ /* case '@': input->keypress.key = LIBTERMINPUT_INS; break; (incompatible with rxvt) */
case 'A': input->keypress.key = LIBTERMINPUT_UP; break;
case 'B': input->keypress.key = LIBTERMINPUT_DOWN; break;
case 'C': input->keypress.key = LIBTERMINPUT_RIGHT; break;
@@ -185,13 +185,32 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx)
case 'G': input->keypress.key = LIBTERMINPUT_BEGIN; break;
case 'H': input->keypress.key = LIBTERMINPUT_HOME; break;
case 'M': input->keypress.key = LIBTERMINPUT_MACRO; break;
- case 'P': input->keypress.key = LIBTERMINPUT_PAUSE; break;
+ case 'P': input->keypress.key = LIBTERMINPUT_F1; break;
+ case 'Q': input->keypress.key = LIBTERMINPUT_F2; break;
+ case 'R': input->keypress.key = LIBTERMINPUT_F3; break;
+ case 'S': input->keypress.key = LIBTERMINPUT_F4; break;
case 'U': input->keypress.key = LIBTERMINPUT_NEXT; break;
case 'V': input->keypress.key = LIBTERMINPUT_PRIOR; break;
case 'Z':
input->keypress.key = LIBTERMINPUT_TAB;
input->keypress.mods |= LIBTERMINPUT_SHIFT;
break;
+ case 'a':
+ input->keypress.key = LIBTERMINPUT_UP;
+ input->keypress.mods |= LIBTERMINPUT_SHIFT;
+ break;
+ case 'b':
+ input->keypress.key = LIBTERMINPUT_DOWN;
+ input->keypress.mods |= LIBTERMINPUT_SHIFT;
+ break;
+ case 'c':
+ input->keypress.key = LIBTERMINPUT_RIGHT;
+ input->keypress.mods |= LIBTERMINPUT_SHIFT;
+ break;
+ case 'd':
+ input->keypress.key = LIBTERMINPUT_LEFT;
+ input->keypress.mods |= LIBTERMINPUT_SHIFT;
+ break;
case 'u':
if (nums[0] > 0x10FFFFULL) {
input->type = LIBTERMINPUT_NONE;
@@ -200,7 +219,21 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx)
encode_utf8(nums[0], input->keypress.symbol);
input->keypress.times = 1;
break;
+ case '$':
+ input->keypress.mods |= LIBTERMINPUT_SHIFT;
+ if (nums[0] >= 200)
+ goto suppress;
+ goto tilde_case;
+ case '@':
+ input->keypress.mods |= LIBTERMINPUT_SHIFT;
+ /* fall through */
+ case '^':
+ input->keypress.mods |= LIBTERMINPUT_CTRL;
+ if (nums[0] >= 200)
+ goto suppress;
+ /* fall through */
case '~':
+ tilde_case:
input->keypress.times = 1;
switch (nums[0]) {
case 1: input->keypress.key = LIBTERMINPUT_HOME; break;
@@ -241,15 +274,13 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx)
input->type = LIBTERMINPUT_BRACKETED_PASTE_END;
return;
default:
- input->type = LIBTERMINPUT_NONE;
- return;
+ goto suppress;
}
if (25 <= nums[0] && nums[0] <= 34)
input->keypress.mods |= LIBTERMINPUT_SHIFT;
break;
default:
- input->type = LIBTERMINPUT_NONE;
- break;
+ goto suppress;
}
break;
case 3:
@@ -260,50 +291,52 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx)
case 'D': input->keypress.key = LIBTERMINPUT_F4; break;
case 'E': input->keypress.key = LIBTERMINPUT_F5; break;
default:
- input->type = LIBTERMINPUT_NONE;
- break;
+ goto suppress;
}
break;
default:
- input->type = LIBTERMINPUT_NONE;
- break;
+ goto suppress;
}
break;
case 'O':
switch (!ctx->key[2] ? ctx->key[1] : 0) {
- case 'A': input->keypress.key = LIBTERMINPUT_UP; break;
- case 'B': input->keypress.key = LIBTERMINPUT_DOWN; break;
- case 'C': input->keypress.key = LIBTERMINPUT_RIGHT; break;
- case 'D': input->keypress.key = LIBTERMINPUT_LEFT; break;
- case 'H': input->keypress.key = LIBTERMINPUT_HOME; break;
- case 'F': input->keypress.key = LIBTERMINPUT_END; break;
- case 'P': input->keypress.key = LIBTERMINPUT_F1; break;
- case 'Q': input->keypress.key = LIBTERMINPUT_F2; break;
- case 'R': input->keypress.key = LIBTERMINPUT_F3; break;
- case 'S': input->keypress.key = LIBTERMINPUT_F4; break;
- case 'p': input->keypress.key = LIBTERMINPUT_KEYPAD_0; break;
- case 'q': input->keypress.key = LIBTERMINPUT_KEYPAD_1; break;
- case 'r': input->keypress.key = LIBTERMINPUT_KEYPAD_2; break;
- case 's': input->keypress.key = LIBTERMINPUT_KEYPAD_3; break;
- case 't': input->keypress.key = LIBTERMINPUT_KEYPAD_4; break;
- case 'u': input->keypress.key = LIBTERMINPUT_KEYPAD_5; break;
- case 'v': input->keypress.key = LIBTERMINPUT_KEYPAD_6; break;
- case 'w': input->keypress.key = LIBTERMINPUT_KEYPAD_7; break;
- case 'x': input->keypress.key = LIBTERMINPUT_KEYPAD_8; break;
- case 'y': input->keypress.key = LIBTERMINPUT_KEYPAD_9; break;
- case 'm': input->keypress.key = LIBTERMINPUT_KEYPAD_MINUS; break;
- case 'l': input->keypress.key = LIBTERMINPUT_KEYPAD_COMMA; break;
- case 'b': input->keypress.key = LIBTERMINPUT_KEYPAD_POINT; break;
- case 'M': input->keypress.key = LIBTERMINPUT_KEYPAD_ENTER; break;
+ case 'A': input->keypress.key = LIBTERMINPUT_UP; break;
+ case 'B': input->keypress.key = LIBTERMINPUT_DOWN; break;
+ case 'C': input->keypress.key = LIBTERMINPUT_RIGHT; break;
+ case 'D': input->keypress.key = LIBTERMINPUT_LEFT; break;
+ case 'H': input->keypress.key = LIBTERMINPUT_HOME; break;
+ case 'F': input->keypress.key = LIBTERMINPUT_END; break;
+ case 'P': input->keypress.key = LIBTERMINPUT_F1; break;
+ case 'Q': input->keypress.key = LIBTERMINPUT_F2; break;
+ case 'R': input->keypress.key = LIBTERMINPUT_F3; break;
+ case 'S': input->keypress.key = LIBTERMINPUT_F4; break;
+ case 'p': input->keypress.key = LIBTERMINPUT_KEYPAD_0; break;
+ case 'q': input->keypress.key = LIBTERMINPUT_KEYPAD_1; break;
+ case 'r': input->keypress.key = LIBTERMINPUT_KEYPAD_2; break;
+ case 's': input->keypress.key = LIBTERMINPUT_KEYPAD_3; break;
+ case 't': input->keypress.key = LIBTERMINPUT_KEYPAD_4; break;
+ case 'u': input->keypress.key = LIBTERMINPUT_KEYPAD_5; break;
+ case 'v': input->keypress.key = LIBTERMINPUT_KEYPAD_6; break;
+ case 'w': input->keypress.key = LIBTERMINPUT_KEYPAD_7; break;
+ case 'x': input->keypress.key = LIBTERMINPUT_KEYPAD_8; break;
+ case 'y': input->keypress.key = LIBTERMINPUT_KEYPAD_9; break;
+ case 'k': input->keypress.key = LIBTERMINPUT_KEYPAD_PLUS; break;
+ case 'm': input->keypress.key = LIBTERMINPUT_KEYPAD_MINUS; break;
+ case 'j': input->keypress.key = LIBTERMINPUT_KEYPAD_TIMES; break;
+ case 'o': input->keypress.key = LIBTERMINPUT_KEYPAD_DIVISION; break;
+ case 'n': input->keypress.key = LIBTERMINPUT_KEYPAD_DECIMAL; break;
+ case 'l': input->keypress.key = LIBTERMINPUT_KEYPAD_COMMA; break;
+ case 'b': input->keypress.key = LIBTERMINPUT_KEYPAD_POINT; break;
+ case 'M': input->keypress.key = LIBTERMINPUT_KEYPAD_ENTER; break;
default:
- input->type = LIBTERMINPUT_NONE;
- break;
+ goto suppress;
}
break;
default:
- /* This shouldn't happen */
+ /* This shouldn't happen (without goto) */
+ suppress:
input->type = LIBTERMINPUT_NONE;
break;
}
diff --git a/libterminput.h b/libterminput.h
index d2f505f..f2f0374 100644
--- a/libterminput.h
+++ b/libterminput.h
@@ -18,7 +18,7 @@ enum libterminput_key {
LIBTERMINPUT_RIGHT,
LIBTERMINPUT_LEFT,
LIBTERMINPUT_BEGIN, /* keypad 5 without numlock */
- LIBTERMINPUT_PAUSE,
+ LIBTERMINPUT_MACRO,
LIBTERMINPUT_TAB, /* backtab if with shift */
LIBTERMINPUT_F1,
LIBTERMINPUT_F2,
@@ -51,11 +51,14 @@ enum libterminput_key {
LIBTERMINPUT_KEYPAD_7,
LIBTERMINPUT_KEYPAD_8,
LIBTERMINPUT_KEYPAD_9,
+ LIBTERMINPUT_KEYPAD_PLUS,
LIBTERMINPUT_KEYPAD_MINUS,
+ LIBTERMINPUT_KEYPAD_TIMES,
+ LIBTERMINPUT_KEYPAD_DIVISION,
+ LIBTERMINPUT_KEYPAD_DECIMAL,
LIBTERMINPUT_KEYPAD_COMMA,
LIBTERMINPUT_KEYPAD_POINT,
LIBTERMINPUT_KEYPAD_ENTER,
- LIBTERMINPUT_MACRO
};
enum libterminput_type {