=== modified file 'man/termkey_strpkey.3' --- man/termkey_strpkey.3 2018-03-29 12:08:54 +0000 +++ man/termkey_strpkey.3 2017-04-10 14:18:08 +0000 @@ -32,13 +32,10 @@ .TP .B TERMKEY_FORMAT_LOWERSPACE Expect lowercase with spaces in for the key name instead of camelCase (for example "\f(CWpage down\fP" instead of "\f(CWPageDown\fP"). -.TP -.B TERMKEY_FORMAT_MOUSE_POS -Expect a mouse event to be followed by its position rendered as "\f(CW@ (col,line)\fP". .PP Before returning, this function canonicalises the \fIkey\fP structure according to the rules given for \fBtermkey_canonicalise\fP(3). .PP -The \fBTERMKEY_FORMAT_WRAPBRACKET\fP option is currently not supported by \fBtermkey_strpkey\fP(). When returning a \fBTERMKEY_TYPE_UNICODE\fP key structure, this function will fill in the \fIutf8\fP member. +The \fBTERMKEY_FORMAT_WRAPBRACKET\fP and \fBTERMKEY_FORMAT_MOUSE_POS\fP options are currently not supported by \fBtermkey_strpkey\fP(). When returning a \fBTERMKEY_TYPE_UNICODE\fP key structure, this function will fill in the \fIutf8\fP member. .SH "RETURN VALUE" After a successful parse, \fBtermkey_strpkey\fP() returns a pointer to the first character of the input it did not consume. If the input string contains more characters then this will point at the first character beyond. If the entire input string was consumed, then this will point at a null byte. If \fBtermkey_strpkey\fP() fails to parse, it returns \fBNULL\fP. After a failed parse, the \fIkey\fP structure may contain partial or invalid results. The structure will only be valid if the function returns a non-\fBNULL\fP result. .SH "SEE ALSO" === modified file 't/12strpkey.c' --- t/12strpkey.c 2018-03-29 12:08:54 +0000 +++ t/12strpkey.c 2013-08-26 01:23:19 +0000 @@ -5,14 +5,11 @@ { TermKey *tk; TermKeyKey key; - TermKeyMouseEvent mouse; - int button, line, col; const char *endp; #define CLEAR_KEY do { key.type = -1; key.code.codepoint = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0) -#define CLEAR_MOUSE do { CLEAR_KEY; mouse = -1; button = -1, line = -1; col = -1; } while(0) - plan_tests(84); + plan_tests(62); tk = termkey_new_abstract("vt100", 0); @@ -118,48 +115,6 @@ is_int(key.modifiers, 0, "key.modifiers for func/5/0"); is_str(endp, "", "consumed entire input for func/5/0"); - CLEAR_MOUSE; - endp = termkey_strpkey(tk, "MousePress(1)", &key, 0); - termkey_interpret_mouse(tk, &key, &mouse, &button, &line, &col); - is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse"); - is_int(mouse, TERMKEY_MOUSE_PRESS, "mouse press event"); - is_int(button, 1, "mouse button 1"); - is_str(endp, "", "consumed entire input for MousePress(1)"); - - CLEAR_MOUSE; - endp = termkey_strpkey(tk, "MousePress(2) @ (3, 5)", &key, TERMKEY_FORMAT_MOUSE_POS); - termkey_interpret_mouse(tk, &key, &mouse, &button, &line, &col); - is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse"); - is_int(mouse, TERMKEY_MOUSE_PRESS, "mouse press event"); - is_int(button, 2, "mouse button 2"); - is_int(col, 3, "mouse column 3"); - is_int(line, 5, "mouse line 5"); - is_str(endp, "", "consumed entire input for MousePress(2) @ (3, 5)"); - - CLEAR_MOUSE; - endp = termkey_strpkey(tk, "MouseRelease(1)", &key, 0); - termkey_interpret_mouse(tk, &key, &mouse, &button, &line, &col); - is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse"); - is_int(mouse, TERMKEY_MOUSE_RELEASE, "mouse release event"); - is_int(button, 0, "mouse button 1 lost"); // TODO: can we recover it? - is_str(endp, "", "consumed entire input for MouseRelease(1)"); - - CLEAR_MOUSE; - endp = termkey_strpkey(tk, "MouseDrag(1)", &key, 0); - termkey_interpret_mouse(tk, &key, &mouse, &button, &line, &col); - is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse"); - is_int(mouse, TERMKEY_MOUSE_DRAG, "mouse drap event"); - is_int(button, 1, "mouse button 1"); - is_str(endp, "", "consumed entire input for MouseDrag(1)"); - - CLEAR_MOUSE; - endp = termkey_strpkey(tk, "MouseUnknown(1)", &key, 0); - termkey_interpret_mouse(tk, &key, &mouse, &button, &line, &col); - is_int(key.type, TERMKEY_TYPE_MOUSE, "key.type for mouse"); - is_int(mouse, TERMKEY_MOUSE_UNKNOWN, "mouse unknown event"); - is_int(button, 0, "mouse button 1 lost"); - is_str(endp, "", "consumed entire input for MouseUnknown(1)"); - termkey_destroy(tk); return exit_status(); === modified file 'termkey.c' --- termkey.c 2018-03-29 12:08:54 +0000 +++ termkey.c 2017-04-10 14:18:08 +0000 @@ -111,9 +111,6 @@ { 0, NULL }, }; -// Mouse event names -static const char *evnames[] = { "Unknown", "Press", "Drag", "Release" }; - #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) #ifdef DEBUG @@ -1376,6 +1373,8 @@ int line, col; termkey_interpret_mouse(tk, key, &ev, &button, &line, &col); + static const char *evnames[] = { "Unknown", "Press", "Drag", "Release" }; + l = snprintf(buffer + pos, len - pos, "Mouse%s(%d)", evnames[ev], button); @@ -1467,8 +1466,6 @@ size_t nbytes; ssize_t snbytes; const char *endstr; - int button; - char event_name[32]; if((endstr = termkey_lookup_keyname_format(tk, str, &key->code.sym, format))) { key->type = TERMKEY_TYPE_KEYSYM; @@ -1478,48 +1475,13 @@ key->type = TERMKEY_TYPE_FUNCTION; str += snbytes; } - else if(sscanf(str, "Mouse%31[^(](%d)%zn", event_name, &button, &snbytes) == 2) { - str += snbytes; - key->type = TERMKEY_TYPE_MOUSE; - - TermKeyMouseEvent ev = TERMKEY_MOUSE_UNKNOWN; - for(size_t i = 0; i < sizeof(evnames)/sizeof(evnames[0]); i++) { - if(strcmp(evnames[i], event_name) == 0) { - ev = TERMKEY_MOUSE_UNKNOWN + i; - break; - } - } - - int code; - switch(ev) { - case TERMKEY_MOUSE_PRESS: - case TERMKEY_MOUSE_DRAG: - code = button - 1; - if(ev == TERMKEY_MOUSE_DRAG) { - code |= 0x20; - } - break; - case TERMKEY_MOUSE_RELEASE: - code = 3; - break; - default: - code = 128; - break; - } - key->code.mouse[0] = code; - - unsigned int line = 0, col = 0; - if((format & TERMKEY_FORMAT_MOUSE_POS) && sscanf(str, " @ (%u,%u)%zn", &col, &line, &snbytes) == 2) { - str += snbytes; - } - termkey_key_set_linecol(key, col, line); - } // Unicode must be last else if(parse_utf8((unsigned const char *)str, strlen(str), &key->code.codepoint, &nbytes) == TERMKEY_RES_KEY) { key->type = TERMKEY_TYPE_UNICODE; fill_utf8(key); str += nbytes; } + // TODO: Consider mouse events? else return NULL;