From 10d3024a6af956bf8cd7dc61a5e41864b6fbc4f6 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Wed, 8 Oct 2008 00:44:33 +0100 Subject: Pass an explicit 'force' parameter into driver's getkey rather than relying on non-zero waittime --- driver-csi.c | 20 ++++++++++---------- termkey-internal.h | 2 +- termkey.c | 11 ++--------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/driver-csi.c b/driver-csi.c index 0c37265..5abc1a4 100644 --- a/driver-csi.c +++ b/driver-csi.c @@ -122,7 +122,7 @@ static void free_driver(void *private) #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) -static termkey_result getkey_csi(termkey_t *tk, size_t introlen, termkey_key *key) +static termkey_result getkey_csi(termkey_t *tk, size_t introlen, termkey_key *key, int force) { termkey_csi *csi = tk->driver_info; @@ -135,7 +135,7 @@ static termkey_result getkey_csi(termkey_t *tk, size_t introlen, termkey_key *ke } if(csi_end >= tk->buffcount) { - if(tk->waittime) + if(!force) return TERMKEY_RES_AGAIN; (*tk->method.emit_codepoint)(tk, '[', key); @@ -223,12 +223,12 @@ static termkey_result getkey_csi(termkey_t *tk, size_t introlen, termkey_key *ke return TERMKEY_RES_KEY; } -static termkey_result getkey_ss3(termkey_t *tk, size_t introlen, termkey_key *key) +static termkey_result getkey_ss3(termkey_t *tk, size_t introlen, termkey_key *key, int force) { termkey_csi *csi = tk->driver_info; if(tk->buffcount < introlen + 1) { - if(tk->waittime) + if(!force) return TERMKEY_RES_AGAIN; (*tk->method.emit_codepoint)(tk, 'O', key); @@ -271,7 +271,7 @@ static termkey_result getkey_ss3(termkey_t *tk, size_t introlen, termkey_key *ke return TERMKEY_RES_KEY; } -static termkey_result getkey(termkey_t *tk, termkey_key *key) +static termkey_result getkey(termkey_t *tk, termkey_key *key, int force) { if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; @@ -283,7 +283,7 @@ static termkey_result getkey(termkey_t *tk, termkey_key *key) if(tk->buffcount == 1) { // This might be an press, or it may want to be part of a longer // sequence - if(tk->waittime) + if(!force) return TERMKEY_RES_AGAIN; (*tk->method.emit_codepoint)(tk, b0, key); @@ -294,10 +294,10 @@ static termkey_result getkey(termkey_t *tk, termkey_key *key) unsigned char b1 = CHARAT(1); if(b1 == '[') - return getkey_csi(tk, 2, key); + return getkey_csi(tk, 2, key, force); if(b1 == 'O') - return getkey_ss3(tk, 2, key); + return getkey_ss3(tk, 2, key, force); if(b1 == 0x1b) { (*tk->method.emit_codepoint)(tk, b0, key); @@ -325,10 +325,10 @@ static termkey_result getkey(termkey_t *tk, termkey_key *key) return metakey_result; } else if(b0 == 0x8f) { - return getkey_ss3(tk, 1, key); + return getkey_ss3(tk, 1, key, force); } else if(b0 == 0x9b) { - return getkey_csi(tk, 1, key); + return getkey_csi(tk, 1, key, force); } else return (*tk->method.getkey_simple)(tk, key); diff --git a/termkey-internal.h b/termkey-internal.h index 57c74b9..d2d67b8 100644 --- a/termkey-internal.h +++ b/termkey-internal.h @@ -10,7 +10,7 @@ struct termkey_driver { void *(*new_driver)(termkey_t *tk); void (*free_driver)(void *); - termkey_result (*getkey)(termkey_t *tk, termkey_key *key); + termkey_result (*getkey)(termkey_t *tk, termkey_key *key, int force); }; struct keyinfo { diff --git a/termkey.c b/termkey.c index 98726fd..a5f73db 100644 --- a/termkey.c +++ b/termkey.c @@ -363,19 +363,12 @@ static termkey_result getkey_simple(termkey_t *tk, termkey_key *key) termkey_result termkey_getkey(termkey_t *tk, termkey_key *key) { - return (*tk->driver.getkey)(tk, key); + return (*tk->driver.getkey)(tk, key, 0); } termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key) { - int old_waittime = tk->waittime; - tk->waittime = 0; - - termkey_result ret = termkey_getkey(tk, key); - - tk->waittime = old_waittime; - - return ret; + return (*tk->driver.getkey)(tk, key, 1); } termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key) -- cgit v1.2.3-70-g09d2