aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ui-curses.c16
-rw-r--r--ui.h2
-rw-r--r--vis-core.h1
-rw-r--r--vis.c20
4 files changed, 20 insertions, 19 deletions
diff --git a/ui-curses.c b/ui-curses.c
index 8f184e3..dc38e2c 100644
--- a/ui-curses.c
+++ b/ui-curses.c
@@ -91,7 +91,6 @@ typedef struct {
enum UiLayout layout; /* whether windows are displayed horizontally or vertically */
TermKey *termkey; /* libtermkey instance to handle keyboard input (stdin or /dev/tty) */
struct termios tio; /* terminal state to restore before exiting */
- char key[64]; /* string representation of last pressed key */
} UiCurses;
struct UiCursesWin {
@@ -1094,10 +1093,9 @@ static bool ui_haskey(Ui *ui) {
return c != ERR;
}
-static const char *ui_getkey(Ui *ui) {
+static bool ui_getkey(Ui *ui, TermKeyKey *key) {
UiCurses *uic = (UiCurses*)ui;
- TermKeyKey key;
- TermKeyResult ret = termkey_getkey(uic->termkey, &key);
+ TermKeyResult ret = termkey_getkey(uic->termkey, key);
if (ret == TERMKEY_RES_EOF) {
int tty = open("/dev/tty", O_RDWR);
@@ -1119,17 +1117,13 @@ static const char *ui_getkey(Ui *ui) {
fd.fd = STDIN_FILENO;
fd.events = POLLIN;
if (poll(&fd, 1, termkey_get_waittime(uic->termkey)) == 0)
- ret = termkey_getkey_force(uic->termkey, &key);
+ ret = termkey_getkey_force(uic->termkey, key);
}
- if (ret != TERMKEY_RES_KEY)
- return NULL;
- termkey_strfkey(uic->termkey, uic->key, sizeof(uic->key), &key, TERMKEY_FORMAT_VIM);
- return uic->key;
-
+ return ret == TERMKEY_RES_KEY;
fatal:
ui_die_msg(ui, "Failed to re-open stdin as /dev/tty\n");
- return NULL;
+ return false;
}
static void ui_terminal_save(Ui *ui) {
diff --git a/ui.h b/ui.h
index 26f2227..f1e6c28 100644
--- a/ui.h
+++ b/ui.h
@@ -66,7 +66,7 @@ struct Ui {
void (*redraw)(Ui*);
void (*update)(Ui*);
void (*suspend)(Ui*);
- const char* (*getkey)(Ui*);
+ bool (*getkey)(Ui*, TermKeyKey*);
bool (*haskey)(Ui*);
void (*terminal_save)(Ui*);
void (*terminal_restore)(Ui*);
diff --git a/vis-core.h b/vis-core.h
index a998586..6ee25f3 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -162,6 +162,7 @@ struct Vis {
Map *options; /* ":set"-options */
Map *keymap; /* key translation before any bindings are matched */
bool keymap_disabled; /* ignore key map for next key press, gets automatically re-enabled */
+ char key[64]; /* last pressed key as reported from the UI */
Buffer input_queue; /* holds pending input keys */
Buffer *keys; /* currently active keys buffer (either the input_queue or a macro) */
bool errorhandler; /* whether we are currently in an error handler, used to avoid recursion */
diff --git a/vis.c b/vis.c
index 085681e..25f7840 100644
--- a/vis.c
+++ b/vis.c
@@ -864,20 +864,26 @@ static void vis_keys_push(Vis *vis, const char *input, size_t pos, bool record)
}
static const char *getkey(Vis *vis) {
- const char *key = vis->ui->getkey(vis->ui);
- if (!key)
+ TermKeyKey key = { 0 };
+ if (!vis->ui->getkey(vis->ui, &key))
return NULL;
vis_info_hide(vis);
bool use_keymap = vis->mode->id != VIS_MODE_INSERT &&
vis->mode->id != VIS_MODE_REPLACE &&
!vis->keymap_disabled;
vis->keymap_disabled = false;
- if (use_keymap) {
- const char *mapped = map_get(vis->keymap, key);
- if (mapped)
- return mapped;
+ if (key.type == TERMKEY_TYPE_UNICODE && use_keymap) {
+ const char *mapped = map_get(vis->keymap, key.utf8);
+ if (mapped) {
+ size_t len = strlen(mapped);
+ if (len < sizeof(key.utf8))
+ memcpy(key.utf8, mapped, len);
+ }
}
- return key;
+
+ TermKey *termkey = vis->ui->termkey_get(vis->ui);
+ termkey_strfkey(termkey, vis->key, sizeof(vis->key), &key, TERMKEY_FORMAT_VIM);
+ return vis->key;
}
bool vis_signal_handler(Vis *vis, int signum, const siginfo_t *siginfo, const void *context) {