aboutsummaryrefslogtreecommitdiff
path: root/vis.c
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-05-01 11:28:16 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-05-01 12:38:31 +0200
commit8b31028096190ce0339e984bf36df5840d868990 (patch)
tree55ae259a65858dd6fe1452a575874d91e8714464 /vis.c
parent1724f24a0c8795e461f7acf8ca94ecae145da96b (diff)
downloadvis-8b31028096190ce0339e984bf36df5840d868990.tar.gz
vis-8b31028096190ce0339e984bf36df5840d868990.tar.xz
vis: further cleanup input handling, introduce vis_keys_feed API
Diffstat (limited to 'vis.c')
-rw-r--r--vis.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/vis.c b/vis.c
index aaf446b..4e4f80f 100644
--- a/vis.c
+++ b/vis.c
@@ -696,21 +696,19 @@ const char *vis_keys_next(Vis *vis, const char *keys) {
return termkey_strpkey(termkey, keys, &key, TERMKEY_FORMAT_VIM);
}
-void vis_keys_input(Vis *vis, const char *input) {
- vis_keys_push(vis, input);
- vis_keys_process(vis);
-}
-
static void vis_keys_process(Vis *vis) {
Buffer *buf = vis->keys;
char *keys = buf->data, *start = keys, *cur = keys, *end;
- bool prefix = false;
+ bool prefix = false, unknown_key = false;
KeyBinding *binding = NULL;
+ vis->keyhandler = true;
while (cur && *cur) {
- if (!(end = (char*)vis_keys_next(vis, cur)))
- goto err; // XXX: can't parse key this should never happen
+ if (!(end = (char*)vis_keys_next(vis, cur))) {
+ unknown_key = true;
+ goto out;
+ }
char tmp = *end;
*end = '\0';
@@ -765,13 +763,15 @@ static void vis_keys_process(Vis *vis) {
}
}
- buffer_put0(buf, start);
- return;
-err:
- buffer_truncate(buf);
+out:
+ if (unknown_key)
+ buffer_truncate(buf);
+ else
+ buffer_put0(buf, start);
+ vis->keyhandler = false;
}
-void vis_keys_push(Vis *vis, const char *input) {
+void vis_keys_feed(Vis *vis, const char *input) {
if (!input)
return;
if (vis->recording)
@@ -780,6 +780,12 @@ void vis_keys_push(Vis *vis, const char *input) {
macro_append(vis->macro_operator, input);
if (!buffer_append0(vis->keys, input))
buffer_truncate(vis->keys);
+ /* if we are being called from within a keyhandler then appending
+ * the new keys to the end of the input queue is enough. they will
+ * be interpreted once the key handler returns and control reaches
+ * back to the vis_keys_process function. */
+ if (!vis->keyhandler)
+ vis_keys_process(vis);
}
static const char *getkey(Vis *vis) {
@@ -927,7 +933,7 @@ int vis_run(Vis *vis, int argc, char *argv[]) {
const char *key;
while ((key = getkey(vis)))
- vis_keys_input(vis, key);
+ vis_keys_feed(vis, key);
if (vis->mode->idle)
timeout = &idle;