/* move one line up */ int sc_hist_up_line(scr_stat *scp) { if (sc_vtb_pos(scp->history, scp->history_pos, -(scp->xsize*scp->ysize)) == sc_vtb_tail(scp->history)) return -1; scp->history_pos = sc_vtb_pos(scp->history, scp->history_pos, -scp->xsize); history_to_screen(scp); return 0; }
/* go to the top of the history buffer */ void sc_hist_end(scr_stat *scp) { scp->history_pos = sc_vtb_pos(scp->history, sc_vtb_tail(scp->history), scp->xsize*scp->ysize); history_to_screen(scp); }
/* copy screen-full of saved lines */ static void history_to_screen(scr_stat *scp) { int pos; int i; pos = scp->history_pos; for (i = 1; i <= scp->ysize; ++i) { pos = sc_vtb_pos(scp->history, pos, -scp->xsize); sc_vtb_copy(scp->history, pos, &scp->vtb, scp->xsize*(scp->ysize - i), scp->xsize); } mark_all(scp); }
static void copy_history(sc_vtb_t *from, sc_vtb_t *to) { int lines; int cols; int cols1; int cols2; int pos; int i; lines = sc_vtb_rows(from); cols1 = sc_vtb_cols(from); cols2 = sc_vtb_cols(to); cols = imin(cols1, cols2); pos = sc_vtb_tail(from); for (i = 0; i < lines; ++i) { sc_vtb_append(from, pos, to, cols); if (cols < cols2) sc_vtb_seek(to, sc_vtb_pos(to, sc_vtb_tail(to), cols2 - cols)); pos = sc_vtb_pos(from, pos, cols1); } }
/* copy cnt of saved lines */ static void history_to_screen_lines(scr_stat *scp, int cnt) { int pos; int i; int lines = imin(cnt, scp->ysize); pos = scp->history_pos; for (i = 1; i <= lines; ++i) { pos = sc_vtb_pos(scp->history, pos, -scp->xsize); sc_vtb_copy(scp->history, pos, &scp->vtb, scp->xsize*(lines - i), scp->xsize); } mark_all(scp); }
/* restore the screen by copying from the history buffer */ int sc_hist_restore(scr_stat *scp) { int ret; if (scp->history_pos != sc_vtb_tail(scp->history)) { scp->history_pos = sc_vtb_tail(scp->history); history_to_screen(scp); ret = 0; } else { ret = 1; } sc_vtb_seek(scp->history, sc_vtb_pos(scp->history, sc_vtb_tail(scp->history), -scp->xsize*scp->ysize)); return ret; }