Added TERMKEY_FORMAT_SPACEMOD

This commit is contained in:
Paul LeoNerd Evans 2013-08-26 00:56:07 +01:00
parent 89ac8b058c
commit 24abb0c59e
6 changed files with 39 additions and 9 deletions

View File

@ -27,6 +27,9 @@ Use the name "\f(CWMeta\fP" or the letter "\f(CWM\fP" instead of "\f(CWAlt\fP" o
.B TERMKEY_FORMAT_WRAPBRACKET .B TERMKEY_FORMAT_WRAPBRACKET
If the key event is a special key instead of unmodified Unicode, wrap it in "\f(CW<brackets>\fP". If the key event is a special key instead of unmodified Unicode, wrap it in "\f(CW<brackets>\fP".
.TP .TP
.B TERMKEY_FORMAT_SPACEMOD
Use spaces instead of hyphens to separate the modifier name(s) from the base key name.
.TP
.B TERMKEY_FORMAT_MOUSE_POS .B TERMKEY_FORMAT_MOUSE_POS
If the event is a mouse event, include the position rendered as "\f(CW@ (col,line)\fP". If the event is a mouse event, include the position rendered as "\f(CW@ (col,line)\fP".
.PP .PP

View File

@ -23,6 +23,9 @@ If the only modifier is \fBTERMKEY_MOD_CTRL\fP on a plain letter, accept it as "
.TP .TP
.B TERMKEY_FORMAT_ALTISMETA .B TERMKEY_FORMAT_ALTISMETA
Use the name "\f(CWMeta\fP" or the letter "\f(CWM\fP" instead of "\f(CWAlt\fP" or "\f(CWA\fP". Use the name "\f(CWMeta\fP" or the letter "\f(CWM\fP" instead of "\f(CWAlt\fP" or "\f(CWA\fP".
.TP
.B TERMKEY_FORMAT_SPACEMOD
Expect spaces instead of hyphens to separate the modifer name(s) from the base key name.
.PP .PP
Before returning, this function canonicalises the \fIkey\fP structure according to the rules given for \fBtermkey_canonicalise\fP(3). Before returning, this function canonicalises the \fIkey\fP structure according to the rules given for \fBtermkey_canonicalise\fP(3).
.PP .PP

View File

@ -8,7 +8,7 @@ int main(int argc, char *argv[])
char buffer[16]; char buffer[16];
size_t len; size_t len;
plan_tests(28); plan_tests(32);
tk = termkey_new_abstract("vt100", 0); tk = termkey_new_abstract("vt100", 0);
@ -38,6 +38,11 @@ int main(int argc, char *argv[])
is_int(len, 6, "length for unicode/b/CTRL longmod"); is_int(len, 6, "length for unicode/b/CTRL longmod");
is_str(buffer, "Ctrl-b", "buffer for unicode/b/CTRL longmod"); is_str(buffer, "Ctrl-b", "buffer for unicode/b/CTRL longmod");
len = termkey_strfkey(tk, buffer, sizeof buffer, &key,
TERMKEY_FORMAT_LONGMOD|TERMKEY_FORMAT_SPACEMOD);
is_int(len, 6, "length for unicode/b/CTRL longmod|spacemod");
is_str(buffer, "Ctrl b", "buffer for unicode/b/CTRL longmod|spacemod");
len = termkey_strfkey(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_CARETCTRL); len = termkey_strfkey(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_CARETCTRL);
is_int(len, 2, "length for unicode/b/CTRL caretctrl"); is_int(len, 2, "length for unicode/b/CTRL caretctrl");
is_str(buffer, "^B", "buffer for unicode/b/CTRL caretctrl"); is_str(buffer, "^B", "buffer for unicode/b/CTRL caretctrl");
@ -79,6 +84,14 @@ int main(int argc, char *argv[])
is_int(len, 4, "length for sym/Up/0 wrapbracket"); is_int(len, 4, "length for sym/Up/0 wrapbracket");
is_str(buffer, "<Up>", "buffer for sym/Up/0 wrapbracket"); is_str(buffer, "<Up>", "buffer for sym/Up/0 wrapbracket");
key.type = TERMKEY_TYPE_KEYSYM;
key.code.sym = TERMKEY_SYM_PAGEUP;
key.modifiers = 0;
len = termkey_strfkey(tk, buffer, sizeof buffer, &key, 0);
is_int(len, 6, "length for sym/PageUp/0");
is_str(buffer, "PageUp", "buffer for sym/PageUp/0");
key.type = TERMKEY_TYPE_FUNCTION; key.type = TERMKEY_TYPE_FUNCTION;
key.code.number = 5; key.code.number = 5;
key.modifiers = 0; key.modifiers = 0;

View File

@ -9,7 +9,7 @@ int main(int argc, char *argv[])
#define CLEAR_KEY do { key.type = -1; key.code.codepoint = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0) #define CLEAR_KEY do { key.type = -1; key.code.codepoint = -1; key.modifiers = -1; key.utf8[0] = 0; } while(0)
plan_tests(53); plan_tests(58);
tk = termkey_new_abstract("vt100", 0); tk = termkey_new_abstract("vt100", 0);
@ -85,6 +85,14 @@ int main(int argc, char *argv[])
is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+longmod"); is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+longmod");
is_str(endp, "", "consumed entire input for unicode/c/ALT altismeta+longmod"); is_str(endp, "", "consumed entire input for unicode/c/ALT altismeta+longmod");
CLEAR_KEY;
endp = termkey_strpkey(tk, "Meta c", &key, TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_LONGMOD|TERMKEY_FORMAT_SPACEMOD);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta+long/lowermod");
is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT altismeta+long/lowermod");
is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta+long/lowermod");
is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+long/lowermod");
is_str(endp, "", "consumed entire input for unicode/c/ALT altismeta+longmod");
CLEAR_KEY; CLEAR_KEY;
endp = termkey_strpkey(tk, "Up", &key, 0); endp = termkey_strpkey(tk, "Up", &key, 0);
is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type for sym/Up/0"); is_int(key.type, TERMKEY_TYPE_KEYSYM, "key.type for sym/Up/0");

View File

@ -1191,6 +1191,8 @@ size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, T
int wrapbracket = (format & TERMKEY_FORMAT_WRAPBRACKET) && int wrapbracket = (format & TERMKEY_FORMAT_WRAPBRACKET) &&
(key->type != TERMKEY_TYPE_UNICODE || key->modifiers != 0); (key->type != TERMKEY_TYPE_UNICODE || key->modifiers != 0);
char sep = (format & TERMKEY_FORMAT_SPACEMOD) ? ' ' : '-';
if(format & TERMKEY_FORMAT_CARETCTRL && if(format & TERMKEY_FORMAT_CARETCTRL &&
key->type == TERMKEY_TYPE_UNICODE && key->type == TERMKEY_TYPE_UNICODE &&
key->modifiers == TERMKEY_KEYMOD_CTRL) { key->modifiers == TERMKEY_KEYMOD_CTRL) {
@ -1219,19 +1221,19 @@ size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, T
} }
if(key->modifiers & TERMKEY_KEYMOD_ALT) { if(key->modifiers & TERMKEY_KEYMOD_ALT) {
l = snprintf(buffer + pos, len - pos, "%s-", mods->alt); l = snprintf(buffer + pos, len - pos, "%s%c", mods->alt, sep);
if(l <= 0) return pos; if(l <= 0) return pos;
pos += l; pos += l;
} }
if(key->modifiers & TERMKEY_KEYMOD_CTRL) { if(key->modifiers & TERMKEY_KEYMOD_CTRL) {
l = snprintf(buffer + pos, len - pos, "%s-", mods->ctrl); l = snprintf(buffer + pos, len - pos, "%s%c", mods->ctrl, sep);
if(l <= 0) return pos; if(l <= 0) return pos;
pos += l; pos += l;
} }
if(key->modifiers & TERMKEY_KEYMOD_SHIFT) { if(key->modifiers & TERMKEY_KEYMOD_SHIFT) {
l = snprintf(buffer + pos, len - pos, "%s-", mods->shift); l = snprintf(buffer + pos, len - pos, "%s%c", mods->shift, sep);
if(l <= 0) return pos; if(l <= 0) return pos;
pos += l; pos += l;
} }
@ -1320,10 +1322,10 @@ const char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermK
return (char *)str; return (char *)str;
} }
const char *hyphen; const char *sep_at;
while((hyphen = strchr(str, '-'))) { while((sep_at = strchr(str, (format & TERMKEY_FORMAT_SPACEMOD) ? ' ' : '-'))) {
size_t n = hyphen - str; size_t n = sep_at - str;
if(n == strlen(mods->alt) && strncmp(mods->alt, str, n) == 0) if(n == strlen(mods->alt) && strncmp(mods->alt, str, n) == 0)
key->modifiers |= TERMKEY_KEYMOD_ALT; key->modifiers |= TERMKEY_KEYMOD_ALT;
@ -1335,7 +1337,7 @@ const char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermK
else else
break; break;
str = hyphen + 1; str = sep_at + 1;
} }
size_t nbytes; size_t nbytes;

View File

@ -215,6 +215,7 @@ typedef enum {
TERMKEY_FORMAT_CARETCTRL = 1 << 1, /* ^X instead of C-X */ TERMKEY_FORMAT_CARETCTRL = 1 << 1, /* ^X instead of C-X */
TERMKEY_FORMAT_ALTISMETA = 1 << 2, /* Meta- or M- instead of Alt- or A- */ TERMKEY_FORMAT_ALTISMETA = 1 << 2, /* Meta- or M- instead of Alt- or A- */
TERMKEY_FORMAT_WRAPBRACKET = 1 << 3, /* Wrap special keys in brackets like <Escape> */ TERMKEY_FORMAT_WRAPBRACKET = 1 << 3, /* Wrap special keys in brackets like <Escape> */
TERMKEY_FORMAT_SPACEMOD = 1 << 4, /* M Foo instead of M-Foo */
TERMKEY_FORMAT_MOUSE_POS = 1 << 8 /* Include mouse position if relevant; @ col,line */ TERMKEY_FORMAT_MOUSE_POS = 1 << 8 /* Include mouse position if relevant; @ col,line */
} TermKeyFormat; } TermKeyFormat;