[hackers] [scroll] Magnetic redraw behaviour || Jochen Sprickerhof

From: <git_AT_suckless.org>
Date: Sat, 25 Apr 2020 22:34:02 +0200 (CEST)

commit 8afdc10fd50174fc2f567d371401834277bf1c40
Author: Jochen Sprickerhof <git_AT_jochen.sprickerhof.de>
AuthorDate: Sat Apr 25 22:33:46 2020 +0200
Commit: Jochen Sprickerhof <git_AT_jochen.sprickerhof.de>
CommitDate: Sat Apr 25 22:33:46 2020 +0200

    Magnetic redraw behaviour

diff --git a/scroll.c b/scroll.c
index e147bbd..8cda0f6 100644
--- a/scroll.c
+++ b/scroll.c
_AT_@ -254,16 +254,19 @@ redraw()
 {
         int rows = 0, x, y;
 
+ if (bottom == NULL)
+ return;
+
         getcursorposition(&x, &y);
 
+ if (y < ws.ws_row-1)
+ y--;
+
         /* wind back bottom pointer by shown history */
         for (; bottom != NULL && TAILQ_NEXT(bottom, entries) != NULL &&
- rows < y - 2; rows++)
+ rows < y - 1; rows++)
                 bottom = TAILQ_NEXT(bottom, entries);
 
- if (rows == 0)
- return;
-
         /* clear screen */
         dprintf(STDOUT_FILENO, "\033[2J");
         /* set cursor position to upper left corner */
_AT_@ -275,12 +278,16 @@ redraw()
         else
                 write(STDOUT_FILENO, bottom->buf, bottom->size);
 
- for (; rows > 0; rows--) {
+ for (rows = ws.ws_row; rows > 0 &&
+ TAILQ_PREV(bottom, tailhead, entries) != NULL; rows--) {
                 bottom = TAILQ_PREV(bottom, tailhead, entries);
                 write(STDOUT_FILENO, bottom->buf, bottom->size);
         }
- /* add new line in front of the shell prompt */
- write(STDOUT_FILENO, "\n", 1);
+
+ if (bottom == TAILQ_FIRST(&head))
+ write(STDOUT_FILENO, "\n", 1);
+ else
+ bottom = TAILQ_NEXT(bottom, entries);
 }
 
 void
Received on Sat Apr 25 2020 - 22:34:02 CEST

This archive was generated by hypermail 2.3.0 : Sat Apr 25 2020 - 22:36:37 CEST