aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-12-10 01:34:40 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-12-10 01:34:40 +0000
commit215b02e77f13354642ff51982a2a6642c943f977 (patch)
tree4fd3196e633c59f1440b74ee3f5bc8bde7ec1b8b
parent9f1e7b34ebfffadf295e3d0adaa19ebd13e01bdd (diff)
downloadtermo-215b02e77f13354642ff51982a2a6642c943f977.tar.gz
termo-215b02e77f13354642ff51982a2a6642c943f977.tar.xz
termo-215b02e77f13354642ff51982a2a6642c943f977.zip
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
-rw-r--r--termkey.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/termkey.c b/termkey.c
index 4df1294..394c1a8 100644
--- a/termkey.c
+++ b/termkey.c
@@ -368,7 +368,16 @@ static void emit_codepoint(termkey_t *tk, long codepoint, termkey_key *key)
if(!key->code.sym) {
key->type = TERMKEY_TYPE_UNICODE;
- key->code.codepoint = codepoint + 0x40;
+ /* 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;
}
else {
@@ -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);