URI:
       redraw upon sigwinch - scroll - scrollbackbuffer program for st
  HTML git clone git://git.suckless.org/scroll
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 6a8eeb702a0cf24de2314d9be9ebf4b6f17c71cc
   DIR parent 037c7992b12222fe1ade1e785ddfc6b1913a427a
  HTML Author: Jochen Sprickerhof <git@jochen.sprickerhof.de>
       Date:   Thu,  9 Apr 2020 23:50:39 +0200
       
       redraw upon sigwinch
       
       Diffstat:
         M scroll.c                            |      39 +++++++++++++++++++++++++++++++
       
       1 file changed, 39 insertions(+), 0 deletions(-)
       ---
   DIR diff --git a/scroll.c b/scroll.c
       @@ -60,6 +60,7 @@ int mfd;
        struct termios dfl;
        struct winsize ws;
        static bool altscreen = false;        /* is alternative screen active */
       +static bool doredraw = false;        /* redraw upon sigwinch */
        
        struct rule {
                const char *seq;
       @@ -110,6 +111,7 @@ sigwinch(int sig)
                if (ioctl(mfd, TIOCSWINSZ, &ws) == -1)
                        die("ioctl:");
                kill(-child, SIGWINCH);
       +        doredraw = true;
        }
        
        void
       @@ -258,6 +260,37 @@ addline(char *buf, size_t size)
        }
        
        void
       +redraw()
       +{
       +        int rows = 0;
       +
       +        /* wind back bottom pointer by one page */
       +        for (; bottom != NULL && TAILQ_NEXT(bottom, entries) != NULL &&
       +            rows < ws.ws_row; rows++)
       +                bottom = TAILQ_NEXT(bottom, entries);
       +
       +        if (rows <= 0) {
       +                return;
       +        }
       +
       +        /* clear screen */
       +        dprintf(STDOUT_FILENO, "\033[2J");
       +        /* set cursor position to upper left corner */
       +        write(STDOUT_FILENO, "\033[0;0H", 6);
       +
       +        /* remove newline of first line as we are at 0,0 already */
       +        if (bottom->size > 0 && bottom->buf[0] == '\n')
       +                write(STDOUT_FILENO, bottom->buf + 1, bottom->size - 1);
       +        else
       +                write(STDOUT_FILENO, bottom->buf, bottom->size);
       +
       +        for (; rows > 0; rows--) {
       +                bottom = TAILQ_PREV(bottom, tailhead, entries);
       +                write(STDOUT_FILENO, bottom->buf, bottom->size);
       +        }
       +}
       +
       +void
        scrollup(int n)
        {
                int rows = 2;
       @@ -437,6 +470,12 @@ main(int argc, char *argv[])
                        if (poll(pfd, 2, -1) == -1 && errno != EINTR)
                                die("poll:");
        
       +                if (doredraw) {
       +                        redraw();
       +                        doredraw = false;
       +                        continue;
       +                }
       +
                        if (pfd[0].revents & POLLIN) {
                                ssize_t n = read(STDIN_FILENO, input, sizeof(input)-1);