aboutsummaryrefslogtreecommitdiff
path: root/termkey.c
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-08-21 20:20:07 +0100
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-08-21 20:20:07 +0100
commita06d010504df8b0a77323bf0ffef9ca6bb7ae6b5 (patch)
treedadecf314926ece6f45601b4081b47f0ddd8c695 /termkey.c
parent95e87a86d50b0cf1f2c1292ff4cd4ff307ca791f (diff)
downloadtermo-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.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/termkey.c b/termkey.c
index 9d03aea..0954ac5 100644
--- a/termkey.c
+++ b/termkey.c
@@ -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;
+}