commit a684e46ca74a3e627d648b7a50db9fe79ae2272e
Author:     Jochen Sprickerhof <[email protected]>
AuthorDate: Thu Apr 2 22:17:23 2020 +0200
Commit:     Jochen Sprickerhof <[email protected]>
CommitDate: Thu Apr 2 22:24:17 2020 +0200

    Fix scrollup line counting

diff --git a/scroll.c b/scroll.c
index 76b6324..56e98ca 100644
--- a/scroll.c
+++ b/scroll.c
@@ -251,36 +251,37 @@ addline(char *buf, size_t size)
 void
 scrollup(void)
 {
-       int rows = 0, start = 0;
+       int rows = - ws.ws_row + 1;
        struct line *bottom_old = bottom;
 
        /* account for last line */
        if(bottom != NULL && TAILQ_PREV(bottom, tailhead, entries) == NULL)
-               start = 2;
+               rows++;
 
        /* wind back bottom pointer by two pages */
        for (; bottom != NULL &&
               TAILQ_NEXT(bottom, entries) != NULL &&
-              rows < 2 * ws.ws_row; rows++)
+              rows <= ws.ws_row; rows++)
                bottom = TAILQ_NEXT(bottom, entries);
 
-       if (rows <= ws.ws_row) {
+       if (rows <= 0) {
                bottom = bottom_old;
                return;
        }
 
        /* move the text in terminal n lines down */
-       dprintf(STDOUT_FILENO, "\033[%dT", rows - ws.ws_row);
+       dprintf(STDOUT_FILENO, "\033[%dT", rows);
        /* set cursor position */
        write(STDOUT_FILENO, "\033[0;0H", 6);
        /* hide cursor */
        write(STDOUT_FILENO, "\033[?25l", 6);
 
        /* print one page */
-       for (rows = 0; rows < ws.ws_row + start; rows++) {
+       for (; rows > 0; rows--) {
                write(STDOUT_FILENO, bottom->buf, bottom->size);
                bottom = TAILQ_PREV(bottom, tailhead, entries);
        }
+       bottom = TAILQ_NEXT(bottom, entries);
 }
 
 void

Reply via email to