From a76057df97157dc76959bcd40649f5953aebc9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 13 Sep 2015 17:49:38 +0200 Subject: vis: rework input handling using libtermkey Key bindings are now specified as symbolic key strings, this will eventually allow run time configurable key mappings. This introduces a bulid time dependency on libtermkey which can be found at: http://www.leonerd.org.uk/code/libtermkey/ --- editor.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'editor.c') diff --git a/editor.c b/editor.c index e06e946..70cc162 100644 --- a/editor.c +++ b/editor.c @@ -230,6 +230,27 @@ void editor_suspend(Editor *ed) { ed->ui->suspend(ed->ui); } +bool editor_mode_map(Mode *mode, const char *name, KeyBinding *binding) { + return map_put(mode->bindings, name, binding); +} + +bool editor_mode_bindings(Mode *mode, KeyBinding **bindings) { + if (!mode->bindings) + mode->bindings = map_new(); + if (!mode->bindings) + return false; + bool success = true; + for (KeyBinding *kb = *bindings; kb->key; kb++) { + if (!editor_mode_map(mode, kb->key, kb)) + success = false; + } + return success; +} + +bool editor_mode_unmap(Mode *mode, const char *name) { + return map_delete(mode->bindings, name); +} + static void window_free(Win *win) { if (!win) return; -- cgit v1.2.3