diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-04-01 00:26:02 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2011-04-01 00:26:02 +0100 |
commit | ee69b33c496fffab14f5783552b0316cdcdef543 (patch) | |
tree | 973f51ae86e5827eb96aa7baa6f063c05e0fb2c3 | |
parent | f1b3dff4c2075d9304dd4c298db433c7d404f3a3 (diff) | |
download | termo-ee69b33c496fffab14f5783552b0316cdcdef543.tar.gz termo-ee69b33c496fffab14f5783552b0316cdcdef543.tar.xz termo-ee69b33c496fffab14f5783552b0316cdcdef543.zip |
Neater implementation of key modifier names for strfkey; put them in a little table
-rw-r--r-- | termkey.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -950,12 +950,23 @@ size_t termkey_snprint_key(TermKey *tk, char *buffer, size_t len, TermKeyKey *ke return termkey_strfkey(tk, buffer, len, key, format); } +struct modnames { + const char *shift, *alt, *ctrl; +} +modnames[] = { + { "S", "A", "C" }, // 0 + { "Shift", "Alt", "Ctrl" }, // LONGMOD + { "S", "M", "C" }, // ALTISMETA + { "Shift", "Meta", "Ctrl" }, // ALTISMETA+LONGMOD +}; + size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format) { size_t pos = 0; size_t l = 0; - int longmod = format & TERMKEY_FORMAT_LONGMOD; + struct modnames *mods = &modnames[!!(format & TERMKEY_FORMAT_LONGMOD) + + !!(format & TERMKEY_FORMAT_ALTISMETA) * 2]; int wrapbracket = (format & TERMKEY_FORMAT_WRAPBRACKET) && (key->type != TERMKEY_TYPE_UNICODE || key->modifiers != 0); @@ -988,22 +999,19 @@ size_t termkey_strfkey(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, T } if(key->modifiers & TERMKEY_KEYMOD_ALT) { - int altismeta = format & TERMKEY_FORMAT_ALTISMETA; - - l = snprintf(buffer + pos, len - pos, longmod ? ( altismeta ? "Meta-" : "Alt-" ) - : ( altismeta ? "M-" : "A-" )); + l = snprintf(buffer + pos, len - pos, "%s-", mods->alt); if(l <= 0) return pos; pos += l; } if(key->modifiers & TERMKEY_KEYMOD_CTRL) { - l = snprintf(buffer + pos, len - pos, longmod ? "Ctrl-" : "C-"); + l = snprintf(buffer + pos, len - pos, "%s-", mods->ctrl); if(l <= 0) return pos; pos += l; } if(key->modifiers & TERMKEY_KEYMOD_SHIFT) { - l = snprintf(buffer + pos, len - pos, longmod ? "Shift-" : "S-"); + l = snprintf(buffer + pos, len - pos, "%s-", mods->shift); if(l <= 0) return pos; pos += l; } |