From: Ali Gholami Rudi Date: Thu, 19 Sep 2013 09:48:05 +0000 (+0430) Subject: term: replace term_hist() with term_scrl() X-Git-Url: https://repo.or.cz/w/fbpad.git/commitdiff_plain/317c6f53d81a0fff326743d08d5ec3b219396397 term: replace term_hist() with term_scrl() --- diff --git a/fbpad.c b/fbpad.c index 81f1fc7..0826052 100644 --- a/fbpad.c +++ b/fbpad.c @@ -38,7 +38,6 @@ static int locked; static char pass[1024]; static int passlen; static int cmdmode; /* execute a command and exit */ -static int histpos; /* scrolling history */ static int readchar(void) { @@ -74,17 +73,8 @@ static struct term *mainterm(void) return TERMOPEN(cterm()) ? &terms[cterm()] : NULL; } -static void histscrl(int pos) -{ - if (pos != histpos) - term_hist(pos); - histpos = pos; -} - static void switchterm(int oidx, int nidx, int show, int save, int load) { - if (load && histpos) - histscrl(0); if (save && TERMOPEN(oidx) && TERMSNAP(oidx)) scr_snap(&terms[oidx]); term_save(&terms[oidx]); @@ -201,10 +191,10 @@ static void directkey(void) passlen = 0; return; case ',': - histscrl(MIN(NHIST, histpos + pad_rows() / 2)); + term_scrl(pad_rows() / 2); return; case '.': - histscrl(MAX(0, histpos - pad_rows() / 2)); + term_scrl(-pad_rows() / 2); return; default: if (strchr(tags, c)) { @@ -215,7 +205,6 @@ static void directkey(void) term_send(ESC); } } - histscrl(0); if (c != -1 && mainterm()) term_send(c); } diff --git a/fbpad.h b/fbpad.h index 7836bda..7dc2c47 100644 --- a/fbpad.h +++ b/fbpad.h @@ -31,10 +31,11 @@ struct term { int dirty[NROWS]; /* changed rows in lazy mode */ struct term_state cur, sav; /* terminal saved state */ int fd; /* terminal file descriptor */ - int histtail; /* the next history row */ + int hrow; /* the next history row in hist[] */ + int hpos; /* scrolling history; position */ int lazy; /* lazy mode */ int pid; /* pid of the terminal program */ - int top, bot; /* terminal top and bot */ + int top, bot; /* terminal scrolling region */ }; void term_load(struct term *term, int visible); @@ -45,7 +46,7 @@ void term_send(int c); void term_exec(char **args); void term_end(void); void term_screenshot(void); -void term_hist(int pos); +void term_scrl(int pos); void term_redraw(int all); /* pad.c */ diff --git a/term.c b/term.c index f24315d..dd07106 100644 --- a/term.c +++ b/term.c @@ -121,7 +121,7 @@ static void draw_cursor(int put) static void lazy_start(void) { - memset(dirty, 0, sizeof(term->dirty)); + memset(dirty, 0, pad_rows() * sizeof(*dirty)); lazy = 1; } @@ -136,6 +136,7 @@ static void lazy_flush(void) if (dirty[row]) _draw_pos(row, col, 1); lazy = 0; + term->hpos = 0; } static void screen_reset(int i, int n) @@ -350,14 +351,16 @@ void term_save(struct term *term) term->lazy = lazy; } +/* redraw the screen; if all is zero, update changed lines only */ void term_redraw(int all) { if (term->fd) { if (all) { lazy_start(); - memset(dirty, 1, sizeof(term->dirty)); + memset(dirty, 1, pad_rows() * sizeof(*dirty)); } - lazy_flush(); + if (all || !term->hpos) + lazy_flush(); } else { if (all) pad_blank(0); @@ -440,7 +443,7 @@ static void blank_rows(int sr, int er) draw_cursor(1); } -#define HISTROW(pos) (term->hist + ((term->histtail + NHIST - (pos)) % NHIST) * pad_cols()) +#define HISTROW(pos) (term->hist + ((term->hrow + NHIST - (pos)) % NHIST) * pad_cols()) static void scrl_rows(int nr) { @@ -448,24 +451,26 @@ static void scrl_rows(int nr) for (i = 0; i < nr; i++) { memcpy(HISTROW(0), screen + i * pad_cols(), pad_cols() * sizeof(screen[0])); - term->histtail = (term->histtail + 1) % NHIST; + term->hrow = (term->hrow + 1) % NHIST; } } -void term_hist(int scrl) +void term_scrl(int scrl) { int i, j; - if (!scrl) { + int hpos = LIMIT(term->hpos + scrl, 0, NHIST); + term->hpos = hpos; + if (!hpos) { lazy_flush(); return; } lazy_start(); - memset(dirty, 1, sizeof(term->dirty)); + memset(dirty, 1, pad_rows() * sizeof(*dirty)); for (i = 0; i < pad_rows(); i++) { - int off = (i - scrl) * pad_cols(); - int *_scr = i < scrl ? HISTROW(scrl - i) : term->screen + off; - short *_fgs = i < scrl ? NULL : term->fgs + off; - short *_bgs = i < scrl ? NULL : term->bgs + off; + int off = (i - hpos) * pad_cols(); + int *_scr = i < hpos ? HISTROW(hpos - i) : term->screen + off; + short *_fgs = i < hpos ? NULL : term->fgs + off; + short *_bgs = i < hpos ? NULL : term->bgs + off; for (j = 0; j < pad_cols(); j++) pad_put(_scr[j], i, j, _fgs ? _fgs[j] : BGCOLOR, _bgs ? _bgs[j] : FGCOLOR);