commit 99596d8aab8dfcde593a69f1a88462ee808b611f
parent f9a8555e8d14d53c18d558a777794d2182718f42
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date: Wed, 12 Feb 2020 23:12:30 +0100
improve scroll behavior for non-pagewide rests
Diffstat:
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/scroll.c b/scroll.c
@@ -164,17 +164,9 @@ addline(char *buf, size_t size)
void
scrollup(void)
{
- int rows;
+ int rows = 0;
int first = 0;
- /* move the text in terminal n lines down */
- dprintf(STDOUT_FILENO, "\033[%dS", ws.ws_row);
-
- /* set cursor position */
- write(STDOUT_FILENO, "\033[0;0H", 6);
- /* hide cursor */
- write(STDOUT_FILENO, "\033[?25l", 6);
-
/* check if the input line is on the bottom of the screen */
if (TAILQ_FIRST(&head) == bottom)
first = 1;
@@ -182,10 +174,21 @@ scrollup(void)
/* wind back bottom pointer by two pages */
for (rows = 0; bottom != NULL && rows < 2 * ws.ws_row; rows++)
bottom = TAILQ_NEXT(bottom, entries);
-
if (bottom == NULL)
bottom = TAILQ_LAST(&head, tailhead);
+ if (rows - ws.ws_row <= 0) {
+ bottom = TAILQ_FIRST(&head);
+ return;
+ }
+
+ /* move the text in terminal n lines down */
+ dprintf(STDOUT_FILENO, "\033[%dT", rows - ws.ws_row);
+ /* set cursor position */
+ write(STDOUT_FILENO, "\033[0;0H", 6);
+ /* hide cursor */
+ write(STDOUT_FILENO, "\033[?25l", 6);
+
/* print one page */
for (; rows > ws.ws_row - first;) {
if (TAILQ_PREV(bottom, tailhead, entries) == NULL)