aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2020-03-14 23:29:53 -0700
committerRob Landley <rob@landley.net>2020-03-16 03:24:01 -0500
commitb580cb38649e61fcbf8c7415d0a6c97d4300fd92 (patch)
tree8fa5dd2ca7566039eb08916eeab8ab9c2fea4cbb
parent4129bbe7c6dabd96879d4ad1a7b3b2a210bca0f7 (diff)
downloadtoybox-b580cb38649e61fcbf8c7415d0a6c97d4300fd92.tar.gz
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.
-rw-r--r--toys/pending/vi.c30
1 files 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.screen_height-2; ++i) TT.screen = text_psol(TT.screen);
+ // TODO: if we're on the bottom visible line, move the cursor up.
+ if (TT.screen > 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.screen_height-2; ++i) TT.screen = text_nsol(TT.screen);
+ // TODO: real vi keeps the x position.
+ if (TT.screen > 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;