Added TERMKEY_FORMAT_LOWERMOD

This commit is contained in:
Paul LeoNerd Evans 2013-08-26 01:14:35 +01:00
parent 24abb0c59e
commit a36648e172
6 changed files with 32 additions and 9 deletions

View File

@ -30,6 +30,9 @@ If the key event is a special key instead of unmodified Unicode, wrap it in "\f(
.B TERMKEY_FORMAT_SPACEMOD .B TERMKEY_FORMAT_SPACEMOD
Use spaces instead of hyphens to separate the modifier name(s) from the base key name. Use spaces instead of hyphens to separate the modifier name(s) from the base key name.
.TP .TP
.B TERMKEY_FORMAT_LOWERMOD
Use lowercase for the modifier 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

@ -26,6 +26,9 @@ Use the name "\f(CWMeta\fP" or the letter "\f(CWM\fP" instead of "\f(CWAlt\fP" o
.TP .TP
.B TERMKEY_FORMAT_SPACEMOD .B TERMKEY_FORMAT_SPACEMOD
Expect spaces instead of hyphens to separate the modifer name(s) from the base key name. Expect spaces instead of hyphens to separate the modifer name(s) from the base key name.
.TP
.B TERMKEY_FORMAT_LOWERMOD
Expect lowercase for the modifier 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(32); plan_tests(36);
tk = termkey_new_abstract("vt100", 0); tk = termkey_new_abstract("vt100", 0);
@ -43,6 +43,16 @@ int main(int argc, char *argv[])
is_int(len, 6, "length for unicode/b/CTRL longmod|spacemod"); is_int(len, 6, "length for unicode/b/CTRL longmod|spacemod");
is_str(buffer, "Ctrl b", "buffer 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_LONGMOD|TERMKEY_FORMAT_LOWERMOD);
is_int(len, 6, "length for unicode/b/CTRL longmod|lowermod");
is_str(buffer, "ctrl-b", "buffer for unicode/b/CTRL longmod|lowermod");
len = termkey_strfkey(tk, buffer, sizeof buffer, &key,
TERMKEY_FORMAT_LONGMOD|TERMKEY_FORMAT_SPACEMOD|TERMKEY_FORMAT_LOWERMOD);
is_int(len, 6, "length for unicode/b/CTRL longmod|spacemod|lowermode");
is_str(buffer, "ctrl b", "buffer for unicode/b/CTRL longmod|spacemod|lowermode");
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");

View File

@ -86,12 +86,12 @@ int main(int argc, char *argv[])
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; CLEAR_KEY;
endp = termkey_strpkey(tk, "Meta c", &key, TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_LONGMOD|TERMKEY_FORMAT_SPACEMOD); endp = termkey_strpkey(tk, "meta c", &key, TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_LONGMOD|TERMKEY_FORMAT_SPACEMOD|TERMKEY_FORMAT_LOWERMOD);
is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta+long/lowermod"); is_int(key.type, TERMKEY_TYPE_UNICODE, "key.type for unicode/c/ALT altismeta+long/space+lowermod");
is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT altismeta+long/lowermod"); is_int(key.code.codepoint, 'c', "key.code.codepoint for unicode/c/ALT altismeta+long/space+lowermod");
is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta+long/lowermod"); is_int(key.modifiers, TERMKEY_KEYMOD_ALT, "key.modifiers for unicode/c/ALT altismeta+long/space+lowermod");
is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+long/lowermod"); is_str(key.utf8, "c", "key.utf8 for unicode/c/ALT altismeta+long/space_lowermod");
is_str(endp, "", "consumed entire input for unicode/c/ALT altismeta+longmod"); is_str(endp, "", "consumed entire input for unicode/c/ALT altismeta+long/space+lowermod");
CLEAR_KEY; CLEAR_KEY;
endp = termkey_strpkey(tk, "Up", &key, 0); endp = termkey_strpkey(tk, "Up", &key, 0);

View File

@ -1178,6 +1178,10 @@ modnames[] = {
{ "Shift", "Alt", "Ctrl" }, // LONGMOD { "Shift", "Alt", "Ctrl" }, // LONGMOD
{ "S", "M", "C" }, // ALTISMETA { "S", "M", "C" }, // ALTISMETA
{ "Shift", "Meta", "Ctrl" }, // ALTISMETA+LONGMOD { "Shift", "Meta", "Ctrl" }, // ALTISMETA+LONGMOD
{ "s", "a", "c" }, // LOWERMOD
{ "shift", "alt", "ctrl" }, // LOWERMOD+LONGMOD
{ "s", "m", "c" }, // LOWERMOD+ALTISMETA
{ "shift", "meta", "ctrl" }, // LOWERMOD+ALTISMETA+LONGMOD
}; };
size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format) size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format)
@ -1186,7 +1190,8 @@ size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, T
size_t l = 0; size_t l = 0;
struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) + struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) +
!!(format & TERMKEY_FORMAT_ALTISMETA) * 2]; !!(format & TERMKEY_FORMAT_ALTISMETA) * 2 +
!!(format & TERMKEY_FORMAT_LOWERMOD) * 4];
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);
@ -1302,7 +1307,8 @@ size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, T
const char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyFormat format) const char *termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, TermKeyFormat format)
{ {
struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) + struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) +
!!(format & TERMKEY_FORMAT_ALTISMETA) * 2]; !!(format & TERMKEY_FORMAT_ALTISMETA) * 2 +
!!(format & TERMKEY_FORMAT_LOWERMOD) * 4];
key->modifiers = 0; key->modifiers = 0;

View File

@ -216,6 +216,7 @@ typedef enum {
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_SPACEMOD = 1 << 4, /* M Foo instead of M-Foo */
TERMKEY_FORMAT_LOWERMOD = 1 << 5, /* meta or m instead of Meta or M */
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;