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, 25 insertions, 20 deletions
@@ -4,7 +4,6 @@ #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 1b3af1e..d6f042b 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -15,7 +15,6 @@ #include <sys/stat.h> #include <fcntl.h> #include <termios.h> -#include <termkey.h> #include "ui-curses.h" #include "vis.h" @@ -1079,14 +1078,23 @@ 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 void ui_needkey(Ui *ui) { - UiCurses *uic = (UiCurses*)ui; - termkey_advisereadable(uic->termkey); +static bool ui_haskey(Ui *ui) { + nodelay(stdscr, TRUE); + int c = getch(); + if (c != ERR) + ungetch(c); + nodelay(stdscr, FALSE); + return c != ERR; } static const char *ui_getkey(Ui *ui) { @@ -1175,7 +1183,9 @@ 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, @@ -1187,7 +1197,7 @@ Ui *ui_curses_new(void) { .die = ui_die, .info = ui_info, .info_hide = ui_info_hide, - .needkey = ui_needkey, + .haskey = ui_haskey, .getkey = ui_getkey, .terminal_save = ui_terminal_save, .terminal_restore = ui_terminal_restore, @@ -3,6 +3,7 @@ #include <stdbool.h> #include <stdarg.h> +#include <termkey.h> /* enable large file optimization for files larger than: */ #define UI_LARGE_FILE_SIZE (1 << 25) @@ -52,6 +53,7 @@ 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*); @@ -65,9 +67,10 @@ struct Ui { void (*update)(Ui*); void (*suspend)(Ui*); const char* (*getkey)(Ui*); - void (*needkey)(Ui*); + bool (*haskey)(Ui*); void (*terminal_save)(Ui*); void (*terminal_restore)(Ui*); + TermKey* (*termkey_get)(Ui*); }; struct UiWin { @@ -1,5 +1,6 @@ /* this file is included from sam.c */ +#include <termkey.h> #include "vis-lua.h" #ifndef VIS_OPEN @@ -632,7 +633,7 @@ static void print_symbolic_keys(Vis *vis, Text *txt) { TERMKEY_SYM_KPEQUALS, }; - TermKey *termkey = vis->termkey; + TermKey *termkey = vis->ui->termkey_get(vis->ui); 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,7 +2,6 @@ #define VIS_CORE_H #include <setjmp.h> -#include <termkey.h> #include "vis.h" #include "register.h" #include "text.h" @@ -175,7 +174,6 @@ 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,6 +19,7 @@ #include <sys/ioctl.h> #include <sys/mman.h> #include <pwd.h> +#include <termkey.h> #include "vis.h" #include "text-util.h" @@ -339,12 +340,6 @@ 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; @@ -403,8 +398,6 @@ 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); } @@ -668,7 +661,7 @@ const char *vis_keys_next(Vis *vis, const char *keys) { if (!keys || !*keys) return NULL; TermKeyKey key; - TermKey *termkey = vis->termkey; + TermKey *termkey = vis->ui->termkey_get(vis->ui); 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 == '>') @@ -924,7 +917,8 @@ int vis_run(Vis *vis, int argc, char *argv[]) { continue; } - vis->ui->needkey(vis->ui); + TermKey *termkey = vis->ui->termkey_get(vis->ui); + termkey_advisereadable(termkey); const char *key; while ((key = getkey(vis))) |
