From 8f92b98848f9366e78c7aa824615bade83971513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 4 May 2016 13:23:44 +0200 Subject: vis: clean up interaction between vis and ui A concrete user interface implementation should not have to depend on libtermkey. Therefore the vis core now uses an independent instance to parse keys. --- vis.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'vis.c') diff --git a/vis.c b/vis.c index 7c1ab78..c05eb3c 100644 --- a/vis.c +++ b/vis.c @@ -19,7 +19,6 @@ #include #include #include -#include #include "vis.h" #include "text-util.h" @@ -350,6 +349,12 @@ Vis *vis_new(Ui *ui, VisEvent *event) { Vis *vis = calloc(1, sizeof(Vis)); if (!vis) return NULL; + const char *term = getenv("TERM"); + if (!term) + term = "xterm"; + vis->termkey = termkey_new_abstract(term, TERMKEY_FLAG_UTF8); + if (!vis->termkey) + goto err; vis->ui = ui; vis->ui->init(vis->ui, vis); vis->tabwidth = 8; @@ -408,6 +413,8 @@ void vis_free(Vis *vis) { map_free(vis_modes[i].bindings); array_release_full(&vis->motions); array_release_full(&vis->textobjects); + if (vis->termkey) + termkey_destroy(vis->termkey); free(vis); } @@ -671,7 +678,7 @@ const char *vis_keys_next(Vis *vis, const char *keys) { if (!keys || !*keys) return NULL; TermKeyKey key; - TermKey *termkey = vis->ui->termkey_get(vis->ui); + TermKey *termkey = vis->termkey; const char *next = NULL; /* first try to parse a special key of the form */ if (*keys == '<' && (next = termkey_strpkey(termkey, keys+1, &key, TERMKEY_FORMAT_VIM)) && *next == '>') @@ -927,8 +934,7 @@ int vis_run(Vis *vis, int argc, char *argv[]) { continue; } - TermKey *termkey = vis->ui->termkey_get(vis->ui); - termkey_advisereadable(termkey); + vis->ui->needkey(vis->ui); const char *key; while ((key = getkey(vis))) -- cgit v1.2.3