commit bdffbbb6cea57ba66bce83ac7ffa09cb827ac4fe
Author:     Jochen Sprickerhof <[email protected]>
AuthorDate: Sat Apr 4 22:35:44 2020 +0200
Commit:     Jochen Sprickerhof <[email protected]>
CommitDate: Sat Apr 4 22:37:30 2020 +0200

    Add line count to scrolldown

diff --git a/scroll.c b/scroll.c
index 782f202..4cb6102 100644
--- 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))

Reply via email to