diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2013-08-26 01:32:35 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2013-08-26 01:32:35 +0100 |
commit | 3b2d8eb8130a5966b28d2426585f6fb077669002 (patch) | |
tree | 67f078959a08a11c7ccf216c6442951e27c2e484 /termkey.c | |
parent | a36648e1721367e3e423be7a567aeeafc25e3f54 (diff) | |
download | termo-3b2d8eb8130a5966b28d2426585f6fb077669002.tar.gz termo-3b2d8eb8130a5966b28d2426585f6fb077669002.tar.xz termo-3b2d8eb8130a5966b28d2426585f6fb077669002.zip |
Added TERMKEY_FORMAT_LOWERSPACE for strfkey() only
Diffstat (limited to 'termkey.c')
-rw-r--r-- | termkey.c | 35 |
1 files changed, 33 insertions, 2 deletions
@@ -1,6 +1,7 @@ #include "termkey.h" #include "termkey-internal.h" +#include <ctype.h> #include <errno.h> #include <poll.h> #include <unistd.h> @@ -1170,6 +1171,29 @@ size_t termkey_snprint_key(TermKey *tk, char *buffer, size_t len, TermKeyKey *ke return termkey_strfkey(tk, buffer, len, key, format); } +/* Similar to snprintf(str, size, "%s", src) except it turns CamelCase into + * space separated values + */ +static int snprint_cameltospaces(char *str, size_t size, const char *src) +{ + int prev_lower = 0; + size_t l = 0; + while(*src && l < size) { + if(isupper(*src) && prev_lower) { + if(str) + str[l++] = ' '; + if(l >= size) + return -1; + } + prev_lower = islower(*src); + str[l++] = tolower(*src++); + } + if(l >= size) + return -1; + str[l] = 0; + return l; +} + static struct modnames { const char *shift, *alt, *ctrl; } @@ -1250,10 +1274,17 @@ size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, T l = snprintf(buffer + pos, len - pos, "%s", key->utf8); break; case TERMKEY_TYPE_KEYSYM: - l = snprintf(buffer + pos, len - pos, "%s", termkey_get_keyname(tk, key->code.sym)); + { + const char *name = termkey_get_keyname(tk, key->code.sym); + if(format & TERMKEY_FORMAT_LOWERSPACE) + l = snprint_cameltospaces(buffer + pos, len - pos, name); + else + l = snprintf(buffer + pos, len - pos, "%s", name); + } break; case TERMKEY_TYPE_FUNCTION: - l = snprintf(buffer + pos, len - pos, "F%d", key->code.number); + l = snprintf(buffer + pos, len - pos, "%c%d", + (format & TERMKEY_FORMAT_LOWERSPACE ? 'f' : 'F'), key->code.number); break; case TERMKEY_TYPE_MOUSE: { |