From d5c3d9c8fe500340c081ea3e0a4b575b3369d0dd Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Fri, 30 Nov 2012 14:43:00 +0000 Subject: Also interpret an intermediate CSI byte if present --- driver-csi.c | 4 ++++ man/termkey_interpret_csi.3 | 6 +++++- t/39csi.c | 11 +++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/driver-csi.c b/driver-csi.c index bb699bd..b116924 100644 --- a/driver-csi.c +++ b/driver-csi.c @@ -255,6 +255,10 @@ static TermKeyResult parse_csi(TermKey *tk, size_t introlen, size_t *csi_len, lo if(argi > 16) break; } + else if(c >= 0x20 && c <= 0x2f) { + *commandp |= c << 16; + break; + } p++; } diff --git a/man/termkey_interpret_csi.3 b/man/termkey_interpret_csi.3 index fa0444d..0939d40 100644 --- a/man/termkey_interpret_csi.3 +++ b/man/termkey_interpret_csi.3 @@ -13,7 +13,11 @@ Link with \fI-ltermkey\fP. .SH DESCRIPTION \fBtermkey_interpret_csi\fP() fills in variables in the passed pointers according to the unrecognised CSI sequence event found in \fIkey\fP. It should be called if \fBtermkey_getkey\fP(3) or similar have returned a key event with the type of \fBTERMKEY_TYPE_UNKNOWN_CSI\fP. Note that it is important to call this function as soon as possible after obtaining a \fBTERMKEY_TYPE_CSI\fP key event; specifically, before calling \fBtermkey_getkey\fP() or \fBtermkey_waitkey\fP() again, as a subsequent call will overwrite the buffer space currently containing this sequence. .PP -The \fIargs\fP array will be filled with the numerical arguments of the CSI sequence. The number of elements available in this array should be given as the initial value of the value pointed to by \fInargs\fP, which will be adjusted to give the number of arguments actually found when the function returns. The \fIcmd\fP variable will contain the CSI command value. If a leading byte was found (such as '\f(CW$\fP') then it will be bitwise-ored with the command value, shifted up by 8 bits. +The \fIargs\fP array will be filled with the numerical arguments of the CSI sequence. The number of elements available in this array should be given as the initial value of the value pointed to by \fInargs\fP, which will be adjusted to give the number of arguments actually found when the function returns. The \fIcmd\fP variable will contain the CSI command value. If a leading byte was found (such as '\f(CW?\fP') then it will be bitwise-ored with the command value, shifted up by 8 bits. If an intermediate byte was found (such as '\f(CW$\fP') then it will be bitwise-ored with the command value, shifted up by 16 bits. +.nf +.sp + *cmd = command | (initial << 8) | (intermediate << 16); +.fi .SH "RETURN VALUE" If passed a \fIkey\fP event of the type \fBTERMKEY_TYPE_UNKNOWN_CSI\fP, this function will return \fBTERMKEY_RES_KEY\fP and will affect the variables whose pointers were passed in, as described above. .PP diff --git a/t/39csi.c b/t/39csi.c index fa9d4a0..9d186f6 100644 --- a/t/39csi.c +++ b/t/39csi.c @@ -9,7 +9,7 @@ int main(int argc, char *argv[]) size_t nargs = 16; unsigned long command; - plan_tests(11); + plan_tests(15); tk = termkey_new_abstract("vt100", 0); @@ -31,7 +31,14 @@ int main(int argc, char *argv[]) is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI ? w"); is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); - is_int(command, '?' << 8 | 'w', "command for unknown CSI"); + is_int(command, '?'<<8 | 'w', "command for unknown CSI"); + + termkey_push_bytes(tk, "\e[?$x", 5); + + is_int(termkey_getkey(tk, &key), TERMKEY_RES_KEY, "getkey yields RES_KEY for CSI ? $x"); + is_int(key.type, TERMKEY_TYPE_UNKNOWN_CSI, "key.type for unknown CSI"); + is_int(termkey_interpret_csi(tk, &key, args, &nargs, &command), TERMKEY_RES_KEY, "interpret_csi yields RES_KEY"); + is_int(command, '$'<<16 | '?'<<8 | 'x', "command for unknown CSI"); termkey_destroy(tk); -- cgit v1.2.3-70-g09d2