tled: switching keymaps when reading a single character - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit 2dc24f819262d48c8a7f6b2d1ce6a7fe992b4310
(DIR) parent c7dcceb5c62060da479326a72bc9e1170f18654c
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Tue, 26 May 2015 08:36:08 +0430
led: switching keymaps when reading a single character
Diffstat:
M led.c | 29 ++++++++++++++++++++++++-----
M vi.c | 3 +--
M vi.h | 2 +-
3 files changed, 26 insertions(+), 8 deletions(-)
---
(DIR) diff --git a/led.c b/led.c
t@@ -36,11 +36,6 @@ static int led_posctx(int dir, int pos)
return dir >= 0 ? pos : xcols - pos - 1;
}
-char *led_keymap(char *kmap, int c)
-{
- return c >= 0 ? kmap_map(kmap, c) : NULL;
-}
-
static char *led_render(char *s0)
{
int n, maxcol = 0;
t@@ -153,6 +148,30 @@ static void led_printparts(char *ai, char *pref, char *main, char *post, char *k
sbuf_free(ln);
}
+char *led_read(char **kmap)
+{
+ static char buf[8];
+ int c = term_read(-1);
+ while (!TK_INT(c)) {
+ switch (c) {
+ case TK_CTL('f'):
+ *kmap = conf_kmapalt();
+ break;
+ case TK_CTL('e'):
+ *kmap = kmap_en[0];
+ break;
+ case TK_CTL('v'):
+ buf[0] = term_read(-1);
+ buf[1] = '\0';
+ return buf;
+ default:
+ return kmap_map(*kmap, c);
+ }
+ c = term_read(-1);
+ }
+ return NULL;
+}
+
static char *led_line(char *pref, char *post, char *ai, int ai_max, int *key, char **kmap)
{
struct sbuf *sb;
(DIR) diff --git a/vi.c b/vi.c
t@@ -56,8 +56,7 @@ static void vi_back(int c)
static char *vi_char(void)
{
- int key = vi_read();
- return TK_INT(key) ? NULL : led_keymap(vi_kmap, key);
+ return led_read(&vi_kmap);
}
static char *vi_prompt(char *msg, char **kmap)
(DIR) diff --git a/vi.h b/vi.h
t@@ -113,8 +113,8 @@ char *term_att(int att, int old);
/* line-oriented input and output */
char *led_prompt(char *pref, char *post, char **kmap);
char *led_input(char *pref, char *post, char *ai, int ai_max, char **kmap);
+char *led_read(char **kmap);
void led_print(char *msg, int row);
-char *led_keymap(char *kmap, int c);
int led_pos(char *s, int pos);
/* ex commands */