diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-08-21 20:20:07 +0100 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-08-21 20:20:07 +0100 |
commit | a06d010504df8b0a77323bf0ffef9ca6bb7ae6b5 (patch) | |
tree | dadecf314926ece6f45601b4081b47f0ddd8c695 /termkey.c | |
parent | 95e87a86d50b0cf1f2c1292ff4cd4ff307ca791f (diff) | |
download | termo-a06d010504df8b0a77323bf0ffef9ca6bb7ae6b5.tar.gz termo-a06d010504df8b0a77323bf0ffef9ca6bb7ae6b5.tar.xz termo-a06d010504df8b0a77323bf0ffef9ca6bb7ae6b5.zip |
Added termkey_snprint_key() to render nice string outputs of key events
Diffstat (limited to 'termkey.c')
-rw-r--r-- | termkey.c | 41 |
1 files changed, 41 insertions, 0 deletions
@@ -855,3 +855,44 @@ termkey_keysym termkey_register_csifunc_full(termkey_t *tk, termkey_type type, t return sym; } + +size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, int longmod) +{ + size_t pos = 0; + size_t l; + + if(key->modifiers & TERMKEY_KEYMOD_CTRL) { + l = snprintf(buffer + pos, len - pos, longmod ? "Ctrl-" : "C-"); + if(l <= 0) return pos; + pos += l; + } + + if(key->modifiers & TERMKEY_KEYMOD_ALT) { + l = snprintf(buffer + pos, len - pos, longmod ? "Alt-" : "A-"); + if(l <= 0) return pos; + pos += l; + } + + if(key->modifiers & TERMKEY_KEYMOD_SHIFT) { + l = snprintf(buffer + pos, len - pos, longmod ? "Shift-" : "S-"); + if(l <= 0) return pos; + pos += l; + } + + switch(key->type) { + case TERMKEY_TYPE_UNICODE: + 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)); + break; + case TERMKEY_TYPE_FUNCTION: + l = snprintf(buffer + pos, len - pos, "F%d", key->code.number); + break; + } + + if(l <= 0) return pos; + pos += l; + + return pos; +} |