Skip to content

Commit

Permalink
vi: fix recent changes.
Browse files Browse the repository at this point in the history
vi was segfaulting because some of the printf() arguments were the wrong
way round. The file content also wasn't getting displayed because [%dH
isn't a correct translation of tty_jump(0, y). Personally, although I
agree that tty_esc() wasn't pulling its weight, I think that tty_jump()
was: the escape sequence's arguments are the wrong way round, they're
both off-by-one, and the rules for the short forms don't make sense to
humans, just to 1970s hardware.

Also remove the implicit flush from the inner redraw loop, which was
causing visible flicker (I've left the others since they don't matter).
  • Loading branch information
enh-google authored and landley committed Jan 11, 2022
1 parent 5c0bb0e commit e7e4229
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions toys/pending/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ static void draw_page()
else if (abs(scroll)>TT.screen_height/2) redraw = 3;

xputsn("\e[H"); // jump to top left
if (redraw&2) xputsn("\e[2J\e[h"); //clear screen
if (redraw&2) xputsn("\e[2J\e[H"); //clear screen
else if (scroll>0) printf("\e[%dL", scroll); //scroll up
else if (scroll<0) printf("\e[%dM", -scroll); //scroll down

Expand All @@ -1388,7 +1388,7 @@ static void draw_page()
end = line;


printf("\e[%uH\e[2K", y+1);
printf("\e[%u;0H\e[2K", y+1);
//find cursor position
aw = crunch_nstr(&end, INT_MAX, bytes, 0, "\t\n", vi_crunch);

Expand Down Expand Up @@ -1453,9 +1453,9 @@ static void draw_page()
scroll++, draw_line++;
else if (scroll>0) scroll--, draw_line++;

printf("\e[%uH", y+1);
printf("\e[%u;0H", y+1);
if (draw_line) {
xputsn("\e[2K");
printf("\e[2K");
if (line && strlen(line)) {
aw = crunch_nstr(&line, clip, bytes, 0, "\t\n", vi_crunch);
crunch_str(&line, TT.screen_width-1, stdout, "\t\n", vi_crunch);
Expand All @@ -1472,7 +1472,7 @@ static void draw_page()
TT.drawn_row = TT.scr_row, TT.drawn_col = clip;

// Finished updating visual area, show status line.
printf("\e[%uH\e[2K", TT.screen_height+1);
printf("\e[%u;0H\e[2K", TT.screen_height+1);
if (TT.vi_mode == 2) printf("\e[1m-- INSERT --\e[m");
if (!TT.vi_mode) {
cx_scr = printf("%s", TT.il->data);
Expand All @@ -1485,8 +1485,9 @@ static void draw_page()
(100*TT.cursor)/(TT.filesize ? : 1), TT.cur_row+1, TT.cur_col+1);
if (TT.cur_col != cx_scr) sprintf(toybuf+strlen(toybuf),"-%d", cx_scr+1);
}
printf("\e[%u;%uH%s\e[%u;%uH", toybuf, TT.screen_height+1,
1+TT.screen_width-strlen(toybuf), cy_scr+1, cx_scr+1);
printf("\e[%u;%uH%s\e[%u;%uH", TT.screen_height+1,
(int) (1+TT.screen_width-strlen(toybuf)),
toybuf, cy_scr+1, cx_scr+1);
xflush(1);
}

Expand Down

0 comments on commit e7e4229

Please sign in to comment.