Pass an explicit 'force' parameter into driver's getkey rather than relying on non-zero waittime

This commit is contained in:
Paul LeoNerd Evans 2008-10-08 00:44:33 +01:00
parent ac6cae29bb
commit 10d3024a6a
3 changed files with 13 additions and 20 deletions

View File

@ -122,7 +122,7 @@ static void free_driver(void *private)
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) #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; 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(csi_end >= tk->buffcount) {
if(tk->waittime) if(!force)
return TERMKEY_RES_AGAIN; return TERMKEY_RES_AGAIN;
(*tk->method.emit_codepoint)(tk, '[', key); (*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; 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; termkey_csi *csi = tk->driver_info;
if(tk->buffcount < introlen + 1) { if(tk->buffcount < introlen + 1) {
if(tk->waittime) if(!force)
return TERMKEY_RES_AGAIN; return TERMKEY_RES_AGAIN;
(*tk->method.emit_codepoint)(tk, 'O', key); (*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; 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) if(tk->buffcount == 0)
return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; 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) { if(tk->buffcount == 1) {
// This might be an <Esc> press, or it may want to be part of a longer // This might be an <Esc> press, or it may want to be part of a longer
// sequence // sequence
if(tk->waittime) if(!force)
return TERMKEY_RES_AGAIN; return TERMKEY_RES_AGAIN;
(*tk->method.emit_codepoint)(tk, b0, key); (*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); unsigned char b1 = CHARAT(1);
if(b1 == '[') if(b1 == '[')
return getkey_csi(tk, 2, key); return getkey_csi(tk, 2, key, force);
if(b1 == 'O') if(b1 == 'O')
return getkey_ss3(tk, 2, key); return getkey_ss3(tk, 2, key, force);
if(b1 == 0x1b) { if(b1 == 0x1b) {
(*tk->method.emit_codepoint)(tk, b0, key); (*tk->method.emit_codepoint)(tk, b0, key);
@ -325,10 +325,10 @@ static termkey_result getkey(termkey_t *tk, termkey_key *key)
return metakey_result; return metakey_result;
} }
else if(b0 == 0x8f) { else if(b0 == 0x8f) {
return getkey_ss3(tk, 1, key); return getkey_ss3(tk, 1, key, force);
} }
else if(b0 == 0x9b) { else if(b0 == 0x9b) {
return getkey_csi(tk, 1, key); return getkey_csi(tk, 1, key, force);
} }
else else
return (*tk->method.getkey_simple)(tk, key); return (*tk->method.getkey_simple)(tk, key);

View File

@ -10,7 +10,7 @@ struct termkey_driver
{ {
void *(*new_driver)(termkey_t *tk); void *(*new_driver)(termkey_t *tk);
void (*free_driver)(void *); 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 { struct keyinfo {

View File

@ -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) 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) termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key)
{ {
int old_waittime = tk->waittime; return (*tk->driver.getkey)(tk, key, 1);
tk->waittime = 0;
termkey_result ret = termkey_getkey(tk, key);
tk->waittime = old_waittime;
return ret;
} }
termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key) termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key)