improve handleinput for reads containing multiple keys - sob - simple output bar
(HTM) git clone git://git.codemadness.org/sob
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 39be364f31f527b59f6280d37eaa88e70fe79712
(DIR) parent 4509683dafe3ff6f26d5dd19e4a2ad892e63d5d0
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Fri, 10 Oct 2014 20:36:33 +0000
improve handleinput for reads containing multiple keys
Diffstat:
M sob.c | 43 ++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 15 deletions(-)
---
(DIR) diff --git a/sob.c b/sob.c
@@ -748,26 +748,39 @@ cleanup(void)
}
static void
-handleinput(const unsigned char *key, size_t len)
+handleinput(const unsigned char *input, size_t len)
{
- size_t i;
+ size_t p = 0, keylen, i;
int ismatch = 0;
+ char buf[BUFSIZ];
- for(i = 0; i < LEN(keybinds); i++) {
- if(len == strlen((char*)keybinds[i].key) &&
- memcmp(key, keybinds[i].key, len) == 0) {
- keybinds[i].func();
- ismatch = 1;
- break;
+ while(p < len) {
+ if(input[p] <= 0x1b) {
+ ismatch = 0;
+ for(i = 0; i < LEN(keybinds); i++) {
+ keylen = strlen((char*)keybinds[i].key);
+ if(strncmp((const char*)&input[p], (const char *)keybinds[i].key, keylen) == 0) {
+ keybinds[i].func();
+ p += keylen;
+ ismatch = 1;
+ break;
+ }
+ }
+ if(!ismatch)
+ p++;
+ } else {
+ for(i = p; input[i] && input[i] > 0x1b; i++)
+ ;
+ buf[0] = '\0';
+ if(i - p < sizeof(buf)) {
+ memcpy(buf, &input[p], i - p);
+ buf[i - p] = '\0';
+ p = i;
+ line_inserttext((char*)buf);
+ line_draw();
+ }
}
}
- if(!ismatch) {
- /* ignore unhandled escape sequence */
- if(key[0] == '\x1b' || iscntrl(key[0]))
- return;
- line_inserttext((char*)key);
- line_draw();
- }
}
static int