Added two more formatting options; CARETCTRL and ALTISMETA
This commit is contained in:
parent
f54687c583
commit
5b24e42d90
4
demo.c
4
demo.c
|
@ -13,7 +13,9 @@ int main(int argc, char *argv[]) {
|
||||||
if(key.type == TERMKEY_TYPE_UNICODE && !key.modifiers)
|
if(key.type == TERMKEY_TYPE_UNICODE && !key.modifiers)
|
||||||
printf("%s\n", key.utf8);
|
printf("%s\n", key.utf8);
|
||||||
else {
|
else {
|
||||||
termkey_snprint_key(tk, buffer, sizeof buffer, &key, 1);
|
termkey_snprint_key(tk, buffer, sizeof buffer, &key, 0);
|
||||||
|
printf("<%s> or ", buffer);
|
||||||
|
termkey_snprint_key(tk, buffer, sizeof buffer, &key, ~0);
|
||||||
printf("<%s>\n", buffer);
|
printf("<%s>\n", buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
termkey.c
19
termkey.c
|
@ -863,6 +863,18 @@ size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key
|
||||||
|
|
||||||
int longmod = format & TERMKEY_FORMAT_LONGMOD;
|
int longmod = format & TERMKEY_FORMAT_LONGMOD;
|
||||||
|
|
||||||
|
if(format & TERMKEY_FORMAT_CARETCTRL) {
|
||||||
|
if(key->type == TERMKEY_TYPE_UNICODE &&
|
||||||
|
key->modifiers == TERMKEY_KEYMOD_CTRL &&
|
||||||
|
key->code.number >= '@' &&
|
||||||
|
key->code.number <= '_') {
|
||||||
|
l = snprintf(buffer + pos, len - pos, "^");
|
||||||
|
if(l <= 0) return pos;
|
||||||
|
pos += l;
|
||||||
|
goto do_codepoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(key->modifiers & TERMKEY_KEYMOD_CTRL) {
|
if(key->modifiers & TERMKEY_KEYMOD_CTRL) {
|
||||||
l = snprintf(buffer + pos, len - pos, longmod ? "Ctrl-" : "C-");
|
l = snprintf(buffer + pos, len - pos, longmod ? "Ctrl-" : "C-");
|
||||||
if(l <= 0) return pos;
|
if(l <= 0) return pos;
|
||||||
|
@ -870,7 +882,10 @@ size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key->modifiers & TERMKEY_KEYMOD_ALT) {
|
if(key->modifiers & TERMKEY_KEYMOD_ALT) {
|
||||||
l = snprintf(buffer + pos, len - pos, longmod ? "Alt-" : "A-");
|
int altismeta = format & TERMKEY_FORMAT_ALTISMETA;
|
||||||
|
|
||||||
|
l = snprintf(buffer + pos, len - pos, longmod ? ( altismeta ? "Meta-" : "Alt-" )
|
||||||
|
: ( altismeta ? "M-" : "A-" ));
|
||||||
if(l <= 0) return pos;
|
if(l <= 0) return pos;
|
||||||
pos += l;
|
pos += l;
|
||||||
}
|
}
|
||||||
|
@ -881,6 +896,8 @@ size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key
|
||||||
pos += l;
|
pos += l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do_codepoint:
|
||||||
|
|
||||||
switch(key->type) {
|
switch(key->type) {
|
||||||
case TERMKEY_TYPE_UNICODE:
|
case TERMKEY_TYPE_UNICODE:
|
||||||
l = snprintf(buffer + pos, len - pos, "%s", key->utf8);
|
l = snprintf(buffer + pos, len - pos, "%s", key->utf8);
|
||||||
|
|
|
@ -133,7 +133,9 @@ termkey_keysym termkey_register_ss3kpalt_full(termkey_t *tk, termkey_type type,
|
||||||
termkey_keysym termkey_register_csifunc_full(termkey_t *tk, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, int number, const char *name);
|
termkey_keysym termkey_register_csifunc_full(termkey_t *tk, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, int number, const char *name);
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TERMKEY_FORMAT_LONGMOD = 1
|
TERMKEY_FORMAT_LONGMOD = 1,
|
||||||
|
TERMKEY_FORMAT_CARETCTRL = 2,
|
||||||
|
TERMKEY_FORMAT_ALTISMETA = 4,
|
||||||
} termkey_format;
|
} termkey_format;
|
||||||
|
|
||||||
size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, termkey_format format);
|
size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, termkey_format format);
|
||||||
|
|
Loading…
Reference in New Issue