scroll

scrollbackbuffer program for st
git clone git://git.suckless.org/scroll
Log | Files | Refs | README

commit bdffbbb6cea57ba66bce83ac7ffa09cb827ac4fe
parent b4f858e3e57f45c3ff0d4c8c28b9aa65ac0dcd88
Author: Jochen Sprickerhof <git@jochen.sprickerhof.de>
Date:   Sat,  4 Apr 2020 22:35:44 +0200

Add line count to scrolldown

Diffstat:
Mscroll.c | 25++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/scroll.c b/scroll.c @@ -286,20 +286,19 @@ scrollup(int n) } void -scrolldown(char *buf, size_t size) +scrolldown(char *buf, size_t size, int n) { - int rows = ws.ws_row; - - /* print one page */ - for (; rows > 0 && bottom != NULL && - TAILQ_PREV(bottom, tailhead, entries) != NULL; rows--) { + bottom = TAILQ_PREV(bottom, tailhead, entries); + /* print n lines */ + for (; n > 0 && bottom != NULL && bottom != TAILQ_FIRST(&head); n--) { bottom = TAILQ_PREV(bottom, tailhead, entries); write(STDOUT_FILENO, bottom->buf, bottom->size); } - if (rows < ws.ws_row && bottom == TAILQ_FIRST(&head)) { + if (bottom == TAILQ_FIRST(&head)) { write(STDOUT_FILENO, "\033[?25h", 6); /* show cursor */ write(STDOUT_FILENO, buf, size); - } + } else + bottom = TAILQ_NEXT(bottom, entries); } void @@ -311,7 +310,7 @@ jumpdown(char *buf, size_t size) for (; TAILQ_NEXT(bottom, entries) != NULL && rows > 0; rows--) bottom = TAILQ_NEXT(bottom, entries); - scrolldown(buf, size); + scrolldown(buf, size, ws.ws_row); } int @@ -395,10 +394,10 @@ main(int argc, char *argv[]) scrollup(ws.ws_row); else if (!altscreen && strncmp(MS_SCROLL_UP, input, n) == 0) scrollup(1); - else if (!altscreen && - (strncmp(KB_SCROLL_DOWN, input, n) == 0 || - strncmp(MS_SCROLL_DOWN, input, n) == 0)) - scrolldown(buf, pos); + else if (!altscreen && strncmp(KB_SCROLL_DOWN, input, n) == 0) + scrolldown(buf, pos, ws.ws_row); + else if (!altscreen && strncmp(MS_SCROLL_DOWN, input, n) == 0) + scrolldown(buf, pos, 1); else if (write(mfd, input, n) == -1) die("write:"); else if (bottom != TAILQ_FIRST(&head))