scroll

scrollbackbuffer program for st
git clone git://git.suckless.org//gitrepos
Log | Files | Refs

commit 038f45363d55ab4eeac9dc2ed9ebbc59a35a9592
parent c9bda1fa200e8707accf1c2d4211af967f54a7d2
Author: Jochen Sprickerhof <git@jochen.sprickerhof.de>
Date:   Mon, 17 Feb 2020 20:15:20 +0100

Add \r\n to the beginning of the buffer

Diffstat:
Mscroll.c | 24+++++++++---------------
1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/scroll.c b/scroll.c @@ -190,15 +190,12 @@ scrollup(void) write(STDOUT_FILENO, "\033[?25l", 6); /* print one page */ - for (; rows > ws.ws_row - first;) { + for (; rows > ws.ws_row - first;rows--) { if (TAILQ_PREV(bottom, tailhead, entries) == NULL) break; bottom = TAILQ_PREV(bottom, tailhead, entries); - if (--rows > ws.ws_row - first) - write(STDOUT_FILENO, bottom->buf, bottom->size); - else /* last line w/o "/r/n" */ - write(STDOUT_FILENO, bottom->buf, bottom->size - 2); + write(STDOUT_FILENO, bottom->buf, bottom->size); } } @@ -209,15 +206,12 @@ scrolldown(void) write(STDOUT_FILENO, "\r\n", 2); /* print one page */ - for (; rows >= 0;) { + for (; rows >= 0;rows--) { if (TAILQ_PREV(bottom, tailhead, entries) == NULL) break; bottom = TAILQ_PREV(bottom, tailhead, entries); - if (--rows > 0) - write(STDOUT_FILENO, bottom->buf, bottom->size); - else /* last line w/o "/r/n" */ - write(STDOUT_FILENO, bottom->buf, bottom->size - 2); + write(STDOUT_FILENO, bottom->buf, bottom->size); } } @@ -304,6 +298,11 @@ main(int argc, char *argv[]) ssize_t n = read(mfd, &c, 1); if (n == -1 && errno != EINTR) die("read:"); + if (c == '\r') { + addline(buf, pos); + memset(buf, 0, size); + pos = 0; + } buf[pos++] = c; if (pos == size) { size *= 2; @@ -311,11 +310,6 @@ main(int argc, char *argv[]) if (buf == NULL) die("realloc:"); } - if (c == '\n') { - addline(buf, pos); - memset(buf, 0, size); - pos = 0; - } if (write(STDOUT_FILENO, &c, 1) == -1) die("write:"); }