diff options
| -rw-r--r-- | main.c | 1 | ||||
| -rw-r--r-- | ui-curses.c | 20 | ||||
| -rw-r--r-- | ui.h | 5 | ||||
| -rw-r--r-- | vis-cmds.c | 3 | ||||
| -rw-r--r-- | vis-core.h | 2 | ||||
| -rw-r--r-- | vis.c | 14 |
6 files changed, 20 insertions, 25 deletions
@@ -4,6 +4,7 @@ #include <wchar.h> #include <ctype.h> #include <errno.h> +#include <stdlib.h> #include "ui-curses.h" #include "vis.h" diff --git a/ui-curses.c b/ui-curses.c index 475225b..1de0f99 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -15,6 +15,7 @@ #include <sys/stat.h> #include <fcntl.h> #include <termios.h> +#include <termkey.h> #include "ui-curses.h" #include "vis.h" @@ -1066,23 +1067,14 @@ static TermKey *ui_termkey_new(int fd) { return termkey; } -static TermKey *ui_termkey_get(Ui *ui) { - UiCurses *uic = (UiCurses*)ui; - return uic->termkey; -} - static void ui_suspend(Ui *ui) { endwin(); raise(SIGSTOP); } -static bool ui_haskey(Ui *ui) { - nodelay(stdscr, TRUE); - int c = getch(); - if (c != ERR) - ungetch(c); - nodelay(stdscr, FALSE); - return c != ERR; +static void ui_needkey(Ui *ui) { + UiCurses *uic = (UiCurses*)ui; + termkey_advisereadable(uic->termkey); } static const char *ui_getkey(Ui *ui) { @@ -1171,9 +1163,7 @@ Ui *ui_curses_new(void) { .init = ui_init, .start = ui_start, .free = ui_curses_free, - .termkey_get = ui_termkey_get, .suspend = ui_suspend, - .resize = ui_resize, .update = ui_update, .window_new = ui_window_new, .window_free = ui_window_free, @@ -1185,7 +1175,7 @@ Ui *ui_curses_new(void) { .die = ui_die, .info = ui_info, .info_hide = ui_info_hide, - .haskey = ui_haskey, + .needkey = ui_needkey, .getkey = ui_getkey, .terminal_save = ui_terminal_save, .terminal_restore = ui_terminal_restore, @@ -3,7 +3,6 @@ #include <stdbool.h> #include <stdarg.h> -#include <termkey.h> typedef struct Ui Ui; typedef struct UiWin UiWin; @@ -48,7 +47,6 @@ struct Ui { bool (*init)(Ui*, Vis*); bool (*start)(Ui*); void (*free)(Ui*); - void (*resize)(Ui*); UiWin* (*window_new)(Ui*, View*, File*, enum UiOption); void (*window_free)(UiWin*); void (*window_focus)(UiWin*); @@ -62,10 +60,9 @@ struct Ui { void (*update)(Ui*); void (*suspend)(Ui*); const char* (*getkey)(Ui*); - bool (*haskey)(Ui*); + void (*needkey)(Ui*); void (*terminal_save)(Ui*); void (*terminal_restore)(Ui*); - TermKey* (*termkey_get)(Ui*); }; struct UiWin { @@ -1,6 +1,5 @@ /* this file is included from sam.c */ -#include <termkey.h> #include "vis-lua.h" #ifndef VIS_OPEN @@ -633,7 +632,7 @@ static void print_symbolic_keys(Vis *vis, Text *txt) { TERMKEY_SYM_KPEQUALS, }; - TermKey *termkey = vis->ui->termkey_get(vis->ui); + TermKey *termkey = vis->termkey; text_appendf(txt, " ␣ (a literal \" \" space symbol must be used to refer to <Space>)\n"); for (size_t i = 0; i < LENGTH(keys); i++) { text_appendf(txt, " <%s>\n", termkey_get_keyname(termkey, keys[i])); @@ -2,6 +2,7 @@ #define VIS_CORE_H #include <setjmp.h> +#include <termkey.h> #include "vis.h" #include "register.h" #include "text.h" @@ -174,6 +175,7 @@ struct Vis { VisEvent *event; Array motions; Array textobjects; + TermKey *termkey; /* libtermkey instance used to parse special keys given by ui */ }; /** stuff used by multiple of the vis-* files */ @@ -19,7 +19,6 @@ #include <sys/ioctl.h> #include <sys/mman.h> #include <pwd.h> -#include <termkey.h> #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 <Key> */ 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))) |
