aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-05-10 22:22:52 +0200
committerMarc André Tanner <mat@brain-dump.org>2016-05-10 22:22:52 +0200
commite2e0162b5bfd2a5ef31f1d09fca4da8962d5d098 (patch)
tree984329f1824e81b0eb2a6f162f5c33ec7c8eb69c
parent0ac9c6210b3b08b2e8a9e7e4de387abcef9afcff (diff)
downloadvis-e2e0162b5bfd2a5ef31f1d09fca4da8962d5d098.tar.gz
vis-e2e0162b5bfd2a5ef31f1d09fca4da8962d5d098.tar.xz
Revert "vis: clean up interaction between vis and ui"
This caused issues on OpenBSD where it crashed the terminal. Also on Mac OS X suspend via ^Z (Ctrl-Z) was missing a \r i.e. the shell prompt was not properly redrawn. While in principle user interfaces should not have to depend on libtermkey, in practice this won't be an issue unless we are adding a non-terminal based UI (which won't happen anytime soon). This reverts commit 8f92b98848f9366e78c7aa824615bade83971513. Close #311
-rw-r--r--main.c1
-rw-r--r--ui-curses.c20
-rw-r--r--ui.h5
-rw-r--r--vis-cmds.c3
-rw-r--r--vis-core.h2
-rw-r--r--vis.c14
6 files changed, 25 insertions, 20 deletions
diff --git a/main.c b/main.c
index 4297c62..3a7f831 100644
--- a/main.c
+++ b/main.c
@@ -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,
diff --git a/ui.h b/ui.h
index b08ff16..fa455af 100644
--- a/ui.h
+++ b/ui.h
@@ -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 {
diff --git a/vis-cmds.c b/vis-cmds.c
index 34f75f2..e52072d 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -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]));
diff --git a/vis-core.h b/vis-core.h
index 68b4e43..6d3b35f 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -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 */
diff --git a/vis.c b/vis.c
index e29371c..3f04c87 100644
--- a/vis.c
+++ b/vis.c
@@ -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)))