aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libterminput.c4
-rw-r--r--test.c108
2 files changed, 110 insertions, 2 deletions
diff --git a/libterminput.c b/libterminput.c
index 136f898..cb946d0 100644
--- a/libterminput.c
+++ b/libterminput.c
@@ -139,7 +139,7 @@ encode_utf8(unsigned long long int codepoint, char buffer[7])
len += 1;
buffer[len] = '\0';
for (; --len; codepoint >>= 6)
- buffer[len] = (char)(codepoint & 0x3FULL);
+ buffer[len] = (char)((codepoint & 0x3FULL) | 0x80ULL);
buffer[0] |= (char)codepoint;
}
@@ -467,7 +467,7 @@ parse_sequence(union libterminput_input *input, struct libterminput_state *ctx)
input->mouseevent.y = (size_t)nums[1] + (size_t)!nums[1];
break;
case 'u':
- if (nums[0] > 0x10FFFFULL || (nums[0] & 0xD800) == 0xD800) {
+ if (nums[0] > 0x10FFFFULL || (nums[0] & 0xFFF800ULL) == 0xD800ULL) {
input->type = LIBTERMINPUT_NONE;
break;
}
diff --git a/test.c b/test.c
index a8f1b27..de1c126 100644
--- a/test.c
+++ b/test.c
@@ -870,6 +870,114 @@ main(void)
TYPE("e", LIBTERMINPUT_NONE);
MOUSEHO("f", 'a' - ' ', 'b' - ' ', 'c' - ' ', 'd' - ' ', 'e' - ' ', 'f' - ' ');
+ TYPE("\033[0u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == 0);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\0');
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[0;1u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == 0);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\0');
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[0;2u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_SHIFT);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\0');
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[1;3u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_META);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\x01');
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[1;4u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_SHIFT | LIBTERMINPUT_META);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\x01');
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[60;5u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_CTRL);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == 60);
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[128;6u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_SHIFT | LIBTERMINPUT_CTRL);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\xC2');
+ TEST(input.keypress.symbol[1] == '\x80');
+ TEST(input.keypress.symbol[2] == '\0');
+
+ TYPE("\033[1114110;7u", LIBTERMINPUT_KEYPRESS); /* 0x10FFFE */
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_META | LIBTERMINPUT_CTRL);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\xF4');
+ TEST(input.keypress.symbol[1] == '\x8F');
+ TEST(input.keypress.symbol[2] == '\xBF');
+ TEST(input.keypress.symbol[3] == '\xBE');
+ TEST(input.keypress.symbol[4] == '\0');
+
+ TYPE("\033[1114112;7u", LIBTERMINPUT_NONE); /* 0x110000 */
+ TYPE("\033[55296;7u", LIBTERMINPUT_NONE); /* 0xD800 */
+ TYPE("\033[55552;7u", LIBTERMINPUT_NONE); /* 0xD900 */
+ TYPE("\033[57088;7u", LIBTERMINPUT_NONE); /* 0xDF00 */
+ TYPE("\033[57343;7u", LIBTERMINPUT_NONE); /* 0xDFFF */
+ TYPE("\033[57344;7u", LIBTERMINPUT_KEYPRESS); /* 0xE000 */
+ TYPE("\033[55295;7u", LIBTERMINPUT_KEYPRESS); /* 0xD7FF */
+
+ TYPE("\033[1114111;7u", LIBTERMINPUT_KEYPRESS); /* 0x10FFFF */
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_META | LIBTERMINPUT_CTRL);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\xF4');
+ TEST(input.keypress.symbol[1] == '\x8F');
+ TEST(input.keypress.symbol[2] == '\xBF');
+ TEST(input.keypress.symbol[3] == '\xBF');
+ TEST(input.keypress.symbol[4] == '\0');
+
+ TYPE("\033[10000;8u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_SHIFT | LIBTERMINPUT_META | LIBTERMINPUT_CTRL);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\xE2');
+ TEST(input.keypress.symbol[1] == '\x9C');
+ TEST(input.keypress.symbol[2] == '\x90');
+ TEST(input.keypress.symbol[3] == '\0');
+
+ TYPE("\033[32;2u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == LIBTERMINPUT_SHIFT);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == ' ');
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[10;9u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == 8);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\n');
+ TEST(input.keypress.symbol[1] == '\0');
+
+ TYPE("\033[10;9u", LIBTERMINPUT_KEYPRESS);
+ TEST(input.keypress.key == LIBTERMINPUT_SYMBOL);
+ TEST(input.keypress.mods == 8);
+ TEST(input.keypress.times == 1);
+ TEST(input.keypress.symbol[0] == '\n');
+ TEST(input.keypress.symbol[1] == '\0');
+
close(fds[1]);
TEST(libterminput_read(fds[0], &input, &ctx) == 0);
close(fds[0]);