From 1d4d908cb8668a1c043a4630d114dcfa219711d7 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Sun, 2 Nov 2008 14:54:33 +0000 Subject: [PATCH] Remeber to handle Esc-prefixed keypresses in base getkey_simple() function - involves some code duplication with CSI driver currently --- termkey.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/termkey.c b/termkey.c index 49b6869..a1904b6 100644 --- a/termkey.c +++ b/termkey.c @@ -351,7 +351,42 @@ static termkey_result getkey_simple(termkey_t *tk, termkey_key *key, int force) { unsigned char b0 = CHARAT(0); - if(b0 < 0xa0) { + if(b0 == 0x1b) { + // Escape-prefixed value? Might therefore be Alt+key + 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; + } + + // Try another key there + tk->buffstart++; + + // Run the full driver + termkey_result metakey_result = (*tk->driver.getkey)(tk, key, force); + + 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: + tk->buffstart--; + break; + } + + return metakey_result; + } + else if(b0 < 0xa0) { // Single byte C0, G0 or C1 - C1 is never UTF-8 initial byte (*tk->method.emit_codepoint)(tk, b0, key); (*tk->method.eat_bytes)(tk, 1);