commit a684e46ca74a3e627d648b7a50db9fe79ae2272e
parent 94da2d2b15ecb4274f2ac2da91807c56743b15a8
Author: Jochen Sprickerhof <git@jochen.sprickerhof.de>
Date: Thu, 2 Apr 2020 22:17:23 +0200
Fix scrollup line counting
Diffstat:
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git 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