diff options
Diffstat (limited to '')
-rw-r--r-- | libterminput.c | 26 | ||||
-rw-r--r-- | test.c | 78 |
2 files changed, 89 insertions, 15 deletions
diff --git a/libterminput.c b/libterminput.c index 10c85cf..2eb6b95 100644 --- a/libterminput.c +++ b/libterminput.c @@ -385,7 +385,7 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx) case 'S': input->keypress.key = LIBTERMINPUT_F4; break; - case 'T': /* TODO test */ + case 'T': /* Parsing output for legacy mouse highlight tracking output. (\e[?1001h) */ ctx->mouse_tracking = 0; nums = numsbuf; @@ -407,12 +407,12 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx) input->mouseevent.event = LIBTERMINPUT_HIGHLIGHT_OUTSIDE; input->mouseevent.mods = 0; input->mouseevent.button = LIBTERMINPUT_BUTTON1; - input->mouseevent.start_x = (size_t)nums[0]; - input->mouseevent.start_y = (size_t)nums[1]; - input->mouseevent.end_x = (size_t)nums[2]; - input->mouseevent.end_y = (size_t)nums[3]; - input->mouseevent.x = (size_t)nums[4]; - input->mouseevent.y = (size_t)nums[5]; + input->mouseevent.start_x = (size_t)nums[0] + (size_t)!nums[0]; + input->mouseevent.start_y = (size_t)nums[1] + (size_t)!nums[1]; + input->mouseevent.end_x = (size_t)nums[2] + (size_t)!nums[2]; + input->mouseevent.end_y = (size_t)nums[3] + (size_t)!nums[3]; + input->mouseevent.x = (size_t)nums[4] + (size_t)!nums[4]; + input->mouseevent.y = (size_t)nums[5] + (size_t)!nums[5]; break; case 'U': input->keypress.key = LIBTERMINPUT_NEXT; break; case 'V': input->keypress.key = LIBTERMINPUT_PRIOR; break; @@ -449,7 +449,7 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx) goto suppress; } break; - case 't': /* TODO test */ + case 't': /* Parsing output for legacy mouse highlight tracking output (\e[?1001h). */ ctx->mouse_tracking = 0; nums = numsbuf; @@ -463,8 +463,8 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx) input->mouseevent.event = LIBTERMINPUT_HIGHLIGHT_INSIDE; input->mouseevent.mods = 0; input->mouseevent.button = LIBTERMINPUT_BUTTON1; - input->mouseevent.x = (size_t)nums[0]; - input->mouseevent.y = (size_t)nums[1]; + input->mouseevent.x = (size_t)nums[0] + (size_t)!nums[0]; + input->mouseevent.y = (size_t)nums[1] + (size_t)!nums[1]; break; case 'u': if (nums[0] > 0x10FFFFULL) { @@ -803,7 +803,7 @@ again: if (!isalpha(p[-1]) && p[-1] != '~' && p[-1] != '@' && p[-1] != '^' && p[-1] != '$') { /* TODO test */ input->type = LIBTERMINPUT_NONE; return 1; - } else if (ctx->key[0] == '[' && ctx->key[1] == '<' && p == &ctx->key[2]) { /* TODO test */ + } else if (ctx->key[0] == '[' && ctx->key[1] == '<' && p == &ctx->key[2]) { input->type = LIBTERMINPUT_NONE; return 1; } else if (ctx->key[0] == '[' && ctx->key[1] == 'M' && (ctx->flags & LIBTERMINPUT_MACRO_ON_CSI_M)) { @@ -845,11 +845,11 @@ again: ctx->mouse_tracking = 3; input->type = LIBTERMINPUT_NONE; return 1; - } else if (ctx->key[0] == '[' && ctx->key[1] == 't' && ctx->stored_head - ctx->stored_tail < 2) { /* TODO test */ + } else if (ctx->key[0] == '[' && ctx->key[1] == 't' && ctx->stored_head - ctx->stored_tail < 2) { ctx->mouse_tracking = 2; input->type = LIBTERMINPUT_NONE; return 1; - } else if (ctx->key[0] == '[' && ctx->key[1] == 'T' && ctx->stored_head - ctx->stored_tail < 6) { /* TODO test */ + } else if (ctx->key[0] == '[' && ctx->key[1] == 'T' && ctx->stored_head - ctx->stored_tail < 6) { ctx->mouse_tracking = 6; input->type = LIBTERMINPUT_NONE; return 1; @@ -376,6 +376,20 @@ main(void) TEST(input.mouseevent.y == (Y));\ } while (0) +#define MOUSEHO(STR, SX, SY, EX, EY, MX, MY)\ + do {\ + TYPE(STR, LIBTERMINPUT_MOUSEEVENT);\ + TEST(input.mouseevent.button == LIBTERMINPUT_BUTTON1);\ + TEST(input.mouseevent.mods == 0);\ + TEST(input.mouseevent.event == LIBTERMINPUT_HIGHLIGHT_OUTSIDE);\ + TEST(input.mouseevent.start_x == (size_t)(SX));\ + TEST(input.mouseevent.start_y == (size_t)(SY));\ + TEST(input.mouseevent.end_x == (size_t)(EX));\ + TEST(input.mouseevent.end_y == (size_t)(EY));\ + TEST(input.mouseevent.x == (size_t)(MX));\ + TEST(input.mouseevent.y == (size_t)(MY));\ + } while (0) + char buffer[512], numbuf[3 * sizeof(int) + 2]; struct libterminput_state ctx; union libterminput_input input; @@ -604,6 +618,20 @@ main(void) for (i = 0; mice[i].str; i++) MOUSE(mice[i].str, mice[i].event, mice[i].button, mice[i].mods, mice[i].x, mice[i].y); + TYPE("\033[<0;1;2", LIBTERMINPUT_NONE); + MOUSE("m", LIBTERMINPUT_RELEASE, LIBTERMINPUT_BUTTON1, 0, 1, 2); + TYPE("\033[<", LIBTERMINPUT_NONE); + TYPE("0;1", LIBTERMINPUT_NONE); + TYPE(";2", LIBTERMINPUT_NONE); + MOUSE("m", LIBTERMINPUT_RELEASE, LIBTERMINPUT_BUTTON1, 0, 1, 2); + + TYPE("\033[<0;1;2", LIBTERMINPUT_NONE); + MOUSE("M", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 1, 2); + TYPE("\033[<", LIBTERMINPUT_NONE); + TYPE("0;1", LIBTERMINPUT_NONE); + TYPE(";2", LIBTERMINPUT_NONE); + MOUSE("M", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 1, 2); + MOUSE("\033[M !#", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 1, 3); MOUSE("\033[M!#!", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON2, 0, 3, 1); MOUSE("\033[M\"#!", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON3, 0, 3, 1); @@ -614,7 +642,8 @@ main(void) MOUSE("\033[M\xac!#", LIBTERMINPUT_PRESS, LIBTERMINPUT_XBUTTON1, LIBTERMINPUT_SHIFT | LIBTERMINPUT_META, 1, 3); MOUSE("\033[M\xb0!#", LIBTERMINPUT_PRESS, LIBTERMINPUT_XBUTTON1, LIBTERMINPUT_CTRL, 1, 3); MOUSE("\033[M\xb1!#", LIBTERMINPUT_PRESS, LIBTERMINPUT_XBUTTON2, LIBTERMINPUT_CTRL, 1, 3); - MOUSE("\033[M ", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 1, 1); + MOUSE("\033[M #", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 1, 3); + MOUSE("\033[M # ", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 3, 1); MOUSE("\033[M\xdf\xff\xff", LIBTERMINPUT_MOTION, 11, 7, 255 - 32, 255 - 32); MOUSE("\033[M\x1f\x1f\x1f", LIBTERMINPUT_MOTION, 15, 7, 255, 255); @@ -638,7 +667,8 @@ main(void) MOUSE("\033[M\xc2\xac!#", LIBTERMINPUT_PRESS, LIBTERMINPUT_XBUTTON1, LIBTERMINPUT_SHIFT | LIBTERMINPUT_META, 1, 3); MOUSE("\033[M\xc2\xb0!#", LIBTERMINPUT_PRESS, LIBTERMINPUT_XBUTTON1, LIBTERMINPUT_CTRL, 1, 3); MOUSE("\033[M\xc2\xb1!#", LIBTERMINPUT_PRESS, LIBTERMINPUT_XBUTTON2, LIBTERMINPUT_CTRL, 1, 3); - MOUSE("\033[M ", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 1, 1); + MOUSE("\033[M #", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 1, 3); + MOUSE("\033[M # ", LIBTERMINPUT_PRESS, LIBTERMINPUT_BUTTON1, 0, 3, 1); TYPE("\033[M \x1f", LIBTERMINPUT_KEYPRESS); TEST(input.keypress.key == LIBTERMINPUT_MACRO); @@ -701,6 +731,50 @@ main(void) libterminput_clear_flags(&ctx, LIBTERMINPUT_DECSET_1005); + MOUSE("\033[t!#", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 1, 3); + MOUSE("\033[t#!", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 3, 1); + MOUSE("\033[t #", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 1, 3); + MOUSE("\033[t# ", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 3, 1); + MOUSE("\033[t\xff\xff", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 255 - 32, 255 - 32); + MOUSE("\033[t\x1f\x1f", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 255, 255); + + TYPE("\033[t!", LIBTERMINPUT_NONE); + MOUSE("#", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 1, 3); + TYPE("\033[t", LIBTERMINPUT_NONE); + MOUSE("#!", LIBTERMINPUT_HIGHLIGHT_INSIDE, LIBTERMINPUT_BUTTON1, 0, 3, 1); + + MOUSEHO("\033[Tabcdef", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + MOUSEHO("\033[T bcdef", 1, 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + MOUSEHO("\033[Ta cdef", 'a' - ' ', 1, 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + MOUSEHO("\033[Tab def", 'a' - ' ', 'b' - ' ', 1, 'd' - ' ', 'e' - ' ', 'f' - ' '); + MOUSEHO("\033[Tabc ef", 'a' - ' ', 'b' - ' ', 'c' - ' ', 1, 'e' - ' ', 'f' - ' '); + MOUSEHO("\033[Tabcd f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 1, 'f' - ' '); + MOUSEHO("\033[Tabcde ", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 1); + MOUSEHO("\033[T\xff\xff\xff\xff\xff\xff", 255 - 32, 255 - 32, 255 - 32, 255 - 32, 255 - 32, 255 - 32); + MOUSEHO("\033[T\x1f\x1f\x1f\x1f\x1f\x1f", 255, 255, 255, 255, 255, 255); + + TYPE("\033[Tabcde", LIBTERMINPUT_NONE); + MOUSEHO("f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + TYPE("\033[Tabcd", LIBTERMINPUT_NONE); + TYPE("e", LIBTERMINPUT_NONE); + MOUSEHO("f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + TYPE("\033[Tabc", LIBTERMINPUT_NONE); + TYPE("d", LIBTERMINPUT_NONE); + TYPE("e", LIBTERMINPUT_NONE); + MOUSEHO("f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + TYPE("\033[Tab", LIBTERMINPUT_NONE); + TYPE("cd", LIBTERMINPUT_NONE); + TYPE("e", LIBTERMINPUT_NONE); + MOUSEHO("f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + TYPE("\033[Ta", LIBTERMINPUT_NONE); + TYPE("bcd", LIBTERMINPUT_NONE); + TYPE("e", LIBTERMINPUT_NONE); + MOUSEHO("f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + TYPE("\033[T", LIBTERMINPUT_NONE); + TYPE("abcd", LIBTERMINPUT_NONE); + TYPE("e", LIBTERMINPUT_NONE); + MOUSEHO("f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' '); + close(fds[1]); TEST(libterminput_read(fds[0], &input, &ctx) == 0); close(fds[0]); |