From b580cb38649e61fcbf8c7415d0a6c97d4300fd92 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Sat, 14 Mar 2020 23:29:53 -0700 Subject: vi: semi-functional ^E/^U and ^F/^B. The forward movement seems okay (no worse than the equivalent arrow key movement), but I haven't yet worked out how to move the cursor back when necessary. Also fix the location of the cursor in ex mode, and stop showing ex commands in bold. --- toys/pending/vi.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/toys/pending/vi.c b/toys/pending/vi.c index 62cbbab0..7b4ca90b 100644 --- a/toys/pending/vi.c +++ b/toys/pending/vi.c @@ -1414,7 +1414,10 @@ static void draw_page() tty_jump(0, TT.screen_height); tty_esc("2K"); if (TT.vi_mode == 2) printf("\x1b[1m-- INSERT --\x1b[m"); - if (!TT.vi_mode) printf("\x1b[1m%s \x1b[m",TT.il->data); + if (!TT.vi_mode) { + cx_scr = printf("%s",TT.il->data); + cy_scr = TT.screen_height; + } sprintf(toybuf, "%zu / %zu,%d,%d", TT.cursor, TT.filesize, TT.cur_row+1, TT.cur_col+1); @@ -1424,10 +1427,8 @@ static void draw_page() tty_jump(TT.screen_width-strlen(toybuf), TT.screen_height); printf("%s", toybuf); - if (TT.vi_mode) tty_jump(cx_scr, cy_scr); - + tty_jump(cx_scr, cy_scr); xflush(1); - } void vi_main(void) @@ -1435,7 +1436,7 @@ void vi_main(void) char keybuf[16] = {0}; char vi_buf[16] = {0}; char utf8_code[8] = {0}; - int utf8_dec_p = 0, vi_buf_pos = 0; + int utf8_dec_p = 0, vi_buf_pos = 0, i; FILE *script = 0; if (FLAG(s)) script = fopen(TT.s, "r"); @@ -1510,6 +1511,25 @@ void vi_main(void) case 'i': TT.vi_mode = 2; break; + case 'B'-'@': + for (i=0; i TT.cursor) TT.cursor = TT.screen; + break; + case 'E'-'@': + TT.screen = text_nsol(TT.screen); + // TODO: real vi keeps the x position. + if (TT.screen > TT.cursor) TT.cursor = TT.screen; + break; + case 'F'-'@': + for (i=0; i TT.cursor) TT.cursor = TT.screen; + break; + case 'U'-'@': + TT.screen = text_psol(TT.screen); + // TODO: if we're on the bottom visible line, move the cursor up. + break; case 27: vi_buf[0] = 0; vi_buf_pos = 0; -- cgit v1.2.3