diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-04-01 10:48:15 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-04-01 10:48:15 +0100 |
commit | a3b88040185e7bc927056475bfcc91b955d8dba5 (patch) | |
tree | eea956114cd4991585e4e06a71bba20faf199727 | |
parent | 59800c356b7737213d80bec5d0b3f0df4b69284c (diff) | |
download | termo-a3b88040185e7bc927056475bfcc91b955d8dba5.tar.gz termo-a3b88040185e7bc927056475bfcc91b955d8dba5.tar.xz termo-a3b88040185e7bc927056475bfcc91b955d8dba5.zip |
Ensure strpkey can parse numbered function keys
-rw-r--r-- | t/11strfkey.c | 14 | ||||
-rw-r--r-- | t/12strpkey.c | 9 | ||||
-rw-r--r-- | termkey.c | 5 |
3 files changed, 25 insertions, 3 deletions
diff --git a/t/11strfkey.c b/t/11strfkey.c index 50cf80a..bdfcf6a 100644 --- a/t/11strfkey.c +++ b/t/11strfkey.c @@ -8,7 +8,7 @@ int main(int argc, char *argv[]) char buffer[16]; size_t len; - plan_tests(24); + plan_tests(28); tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS); @@ -79,6 +79,18 @@ int main(int argc, char *argv[]) is_int(len, 4, "length for sym/Up/0 wrapbracket"); is_str(buffer, "<Up>", "buffer for sym/Up/0 wrapbracket"); + key.type = TERMKEY_TYPE_FUNCTION; + key.code.number = 5; + key.modifiers = 0; + + len = termkey_strfkey(tk, buffer, sizeof buffer, &key, 0); + is_int(len, 2, "length for func/5/0"); + is_str(buffer, "F5", "buffer for func/5/0"); + + len = termkey_strfkey(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_WRAPBRACKET); + is_int(len, 4, "length for func/5/0 wrapbracket"); + is_str(buffer, "<F5>", "buffer for func/5/0 wrapbracket"); + termkey_destroy(tk); return exit_status(); diff --git a/t/12strpkey.c b/t/12strpkey.c index 71c3f5d..363d6e8 100644 --- a/t/12strpkey.c +++ b/t/12strpkey.c @@ -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) - plan_tests(44); + plan_tests(48); tk = termkey_new(0, TERMKEY_FLAG_NOTERMIOS); @@ -84,6 +84,13 @@ int main(int argc, char *argv[]) is_int(key.code.sym, TERMKEY_SYM_UP, "key.code.codepoint for sym/Up/0"); is_int(key.modifiers, 0, "key.modifiers for sym/Up/0"); + CLEAR_KEY; + res = termkey_strpkey(tk, "F5", &key, 0); + is_int(res, TERMKEY_RES_KEY, "result for func/5/0"); + is_int(key.type, TERMKEY_TYPE_FUNCTION, "key.type for func/5/0"); + is_int(key.code.number, 5, "key.code.number for func/5/0"); + is_int(key.modifiers, 0, "key.modifiers for func/5/0"); + termkey_destroy(tk); return exit_status(); @@ -1122,7 +1122,10 @@ TermKeyResult termkey_strpkey(TermKey *tk, const char *str, TermKeyKey *key, Ter else if((key->code.sym = termkey_keyname2sym(tk, str)) != TERMKEY_SYM_UNKNOWN) { key->type = TERMKEY_TYPE_KEYSYM; } - // TODO: Consider function keys + else if(sscanf(str, "F%d", &key->code.number) == 1) { + key->type = TERMKEY_TYPE_FUNCTION; + } + // TODO: Consider mouse events? else { return TERMKEY_RES_NONE; } |