From 86933f18364a249ca67b4b916e83edbb429e091f Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Mon, 3 Nov 2008 14:46:42 +0000 Subject: Reuse common Esc-prefix code in getkey_simple() from CSI driver; avoids code duplication --- driver-csi.c | 49 +++++-------------------------------------------- 1 file changed, 5 insertions(+), 44 deletions(-) diff --git a/driver-csi.c b/driver-csi.c index 6b3f9b0..29da086 100644 --- a/driver-csi.c +++ b/driver-csi.c @@ -298,50 +298,11 @@ static termkey_result getkey(termkey_t *tk, termkey_key *key, int force) // Now we're sure at least 1 byte is valid unsigned char b0 = CHARAT(0); - if(b0 == 0x1b) { - if(tk->buffcount == 1) { - // This might be an press, or it may want to be part of a longer - // sequence - if(!force) - return TERMKEY_RES_AGAIN; - - (*tk->method.emit_codepoint)(tk, b0, key); - (*tk->method.eat_bytes)(tk, 1); - return TERMKEY_RES_KEY; - } - - unsigned char b1 = CHARAT(1); - - if(b1 == '[') - return getkey_csi(tk, 2, key, force); - - if(b1 == 'O') - return getkey_ss3(tk, 2, key, force); - - if(b1 == 0x1b) { - (*tk->method.emit_codepoint)(tk, b0, key); - (*tk->method.eat_bytes)(tk, 1); - return TERMKEY_RES_KEY; - } - - tk->buffstart++; - - termkey_result metakey_result = termkey_getkey(tk, key); - - switch(metakey_result) { - case TERMKEY_RES_KEY: - key->modifiers |= TERMKEY_KEYMOD_ALT; - tk->buffstart--; - (*tk->method.eat_bytes)(tk, 1); - break; - - case TERMKEY_RES_NONE: - case TERMKEY_RES_EOF: - case TERMKEY_RES_AGAIN: - break; - } - - return metakey_result; + if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == '[') { + return getkey_csi(tk, 2, key, force); + } + else if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == 'O') { + return getkey_ss3(tk, 2, key, force); } else if(b0 == 0x8f) { return getkey_ss3(tk, 1, key, force); -- cgit v1.2.3-70-g09d2