diff options
author | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-12-06 00:03:48 +0000 |
---|---|---|
committer | Paul LeoNerd Evans <leonerd@leonerd.org.uk> | 2008-12-06 00:03:48 +0000 |
commit | c10d6f02e40d079f7bb266de566f2d33f09a68b5 (patch) | |
tree | 37c51e4d1e21d9ad9bf93dcae667ff875cfa44b9 | |
parent | 97a47e9b160907455831109549a320b5b3b4994d (diff) | |
download | termo-c10d6f02e40d079f7bb266de566f2d33f09a68b5.tar.gz termo-c10d6f02e40d079f7bb266de566f2d33f09a68b5.tar.xz termo-c10d6f02e40d079f7bb266de566f2d33f09a68b5.zip |
Make sure only to slide buffer down when returning a real key to the user, or else it might upset the meta-key logic when it returns
-rw-r--r-- | termkey.c | 17 |
1 files changed, 10 insertions, 7 deletions
@@ -318,13 +318,6 @@ static void eat_bytes(termkey_t *tk, size_t count) tk->buffstart += count; tk->buffcount -= count; - - size_t halfsize = tk->buffsize / 2; - - if(tk->buffstart > halfsize) { - memcpy(tk->buffer, tk->buffer + halfsize, halfsize); - tk->buffstart -= halfsize; - } } static inline unsigned int utf8_seqlen(long codepoint) @@ -444,6 +437,16 @@ static termkey_result getkey(termkey_t *tk, termkey_key *key, int force) #ifdef DEBUG print_key(tk, key); fprintf(stderr, "\n"); #endif + // Slide the data down to stop it running away + { + size_t halfsize = tk->buffsize / 2; + + if(tk->buffstart > halfsize) { + memcpy(tk->buffer, tk->buffer + halfsize, halfsize); + tk->buffstart -= halfsize; + } + } + /* fallthrough */ case TERMKEY_RES_EOF: return ret; |