tvi: do not overwrite lines in input mode - 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 2b735a5576c57027328c3b46e8dadc626423b10e
(DIR) parent 4f07e5004a8b33bdafd6dd436612ba97ff016df6
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Tue, 9 Jun 2015 09:15:11 +0430
vi: do not overwrite lines in input mode
Diffstat:
M led.c | 4 +++-
M term.c | 11 +++++++++++
M vi.c | 12 ++++++++++++
M vi.h | 1 +
4 files changed, 27 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/led.c b/led.c
t@@ -169,11 +169,13 @@ static void led_printparts(char *ai, char *pref, char *main, char *post, char *k
ren_pos(sbuf_buf(ln), off - 1) < 0 ? -1 : +1;
sbuf_cut(ln, len);
}
+ term_record();
sbuf_str(ln, post);
led_print(sbuf_buf(ln), -1);
pos = ren_cursor(sbuf_buf(ln), ren_pos(sbuf_buf(ln), MAX(0, off - 1)));
term_pos(-1, led_pos(sbuf_buf(ln), pos + idir));
sbuf_free(ln);
+ term_commit();
}
char *led_read(char **kmap)
t@@ -299,10 +301,10 @@ char *led_input(char *pref, char *post, char *ai, int ai_max, char **kmap)
ai[ai_len] = '\0';
}
pref = NULL;
- term_kill();
free(ln);
if (key != '\n')
break;
+ term_room(1);
while (ai_max && post[0] && (post[0] == ' ' || post[0] == '\t'))
post++;
}
(DIR) diff --git a/term.c b/term.c
t@@ -85,6 +85,17 @@ void term_kill(void)
term_out("\33[K");
}
+void term_room(int n)
+{
+ char cmd[16];
+ if (n < 0)
+ sprintf(cmd, "\33[%dM", -n);
+ if (n > 0)
+ sprintf(cmd, "\33[%dL", n);
+ if (n)
+ term_out(cmd);
+}
+
void term_pos(int r, int c)
{
char buf[32] = "\r";
(DIR) diff --git a/vi.c b/vi.c
t@@ -28,6 +28,7 @@ static void vi_drawmsg(void)
vi_msg[0] = '\0';
}
+/* redraw the screen */
static void vi_draw(int xcol)
{
int i;
t@@ -41,6 +42,15 @@ static void vi_draw(int xcol)
term_commit();
}
+/* update the screen by removing lines r1 to r2 before an input command */
+static void vi_drawrm(int r1, int r2, int newln)
+{
+ r1 = MIN(MAX(r1, xtop), xtop + xrows);
+ r2 = MIN(MAX(r2, xtop), xtop + xrows);
+ term_pos(r1 - xtop, 0);
+ term_room(r1 - r2 + newln);
+}
+
static int vi_buf[128];
static int vi_buflen;
t@@ -600,6 +610,7 @@ static void vi_change(int r1, int o1, int r2, int o2, int lnmode)
free(region);
pref = lnmode ? vi_indents(lbuf_get(xb, r1)) : uc_sub(lbuf_get(xb, r1), 0, o1);
post = lnmode ? uc_dup("\n") : uc_sub(lbuf_get(xb, r2), o2, -1);
+ vi_drawrm(r1, r2, 0);
rep = vi_input(pref, post, &row, &off);
if (rep) {
lbuf_rm(xb, r1, r2 + 1);
t@@ -759,6 +770,7 @@ static int vc_insert(int cmd)
off = xoff + 1;
pref = ln && cmd != 'o' && cmd != 'O' ? uc_sub(ln, 0, off) : vi_indents(ln);
post = ln && cmd != 'o' && cmd != 'O' ? uc_sub(ln, off, -1) : uc_dup("\n");
+ vi_drawrm(xrow, xrow, cmd == 'o' || cmd == 'O');
rep = vi_input(pref, post, &row, &off);
if ((cmd == 'o' || cmd == 'O') && !lbuf_len(xb))
lbuf_put(xb, 0, "\n");
(DIR) diff --git a/vi.h b/vi.h
t@@ -110,6 +110,7 @@ void term_chr(int ch);
void term_pos(int r, int c);
void term_clear(void);
void term_kill(void);
+void term_room(int n);
int term_rows(void);
int term_cols(void);
int term_read(int timeout);