Represent Ctrl-letter in lowercase in the struct, so as one day to be able to do Ctrl-Shift-letter. Make sure ^X notation is still capital

This commit is contained in:
Paul LeoNerd Evans 2008-12-10 01:34:40 +00:00
parent 9f1e7b34eb
commit 215b02e77f
1 changed files with 31 additions and 15 deletions

View File

@ -368,6 +368,15 @@ static void emit_codepoint(termkey_t *tk, long codepoint, termkey_key *key)
if(!key->code.sym) {
key->type = TERMKEY_TYPE_UNICODE;
/* Generically modified Unicode ought not report the SHIFT state, or else
* we get into complicationg trying to report Shift-; vs : and so on...
* In order to be able to represent Ctrl-Shift-A as CTRL modified
* unicode A, we need to call Ctrl-A simply 'a', lowercase
*/
if(codepoint+0x40 >= 'A' && codepoint+0x40 <= 'Z')
// it's a letter - use lowecase instead
key->code.codepoint = codepoint + 0x60;
else
key->code.codepoint = codepoint + 0x40;
key->modifiers = TERMKEY_KEYMOD_CTRL;
}
@ -853,24 +862,33 @@ size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key
int wrapbracket = (format & TERMKEY_FORMAT_WRAPBRACKET) &&
(key->type != TERMKEY_TYPE_UNICODE || key->modifiers != 0);
if(format & TERMKEY_FORMAT_CARETCTRL &&
key->type == TERMKEY_TYPE_UNICODE &&
key->modifiers == TERMKEY_KEYMOD_CTRL) {
long codepoint = key->code.codepoint;
// Handle some of the special casesfirst
if(codepoint >= 'a' && codepoint <= 'z') {
l = snprintf(buffer + pos, len - pos, wrapbracket ? "<^%c>" : "^%c", (char)codepoint - 0x20);
if(l <= 0) return pos;
pos += len;
return pos;
}
else if((codepoint >= '@' && codepoint < 'A') ||
(codepoint > 'Z' && codepoint <= '_')) {
l = snprintf(buffer + pos, len - pos, wrapbracket ? "<^%c>" : "^%c", (char)codepoint);
if(l <= 0) return pos;
pos += len;
return pos;
}
}
if(wrapbracket) {
l = snprintf(buffer + pos, len - pos, "<");
if(l <= 0) return pos;
pos += l;
}
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_ALT) {
int altismeta = format & TERMKEY_FORMAT_ALTISMETA;
@ -892,8 +910,6 @@ size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key
pos += l;
}
do_codepoint:
switch(key->type) {
case TERMKEY_TYPE_UNICODE:
l = snprintf(buffer + pos, len - pos, "%s", key->utf8);