scroll

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

commit b4f858e3e57f45c3ff0d4c8c28b9aa65ac0dcd88
parent ab4da6cf310185378d7c81a0be5c1849760d93c7
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Sat,  4 Apr 2020 22:27:54 +0200

refactor line input handling

Diffstat:
Mscroll.c | 34++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/scroll.c b/scroll.c @@ -410,31 +410,29 @@ main(int argc, char *argv[]) if (n == -1 && errno != EINTR) die("read:"); + if (write(STDOUT_FILENO, input, n) == -1) + die("write:"); + /* don't save clear screen esc sequences in log */ - if (strncmp("\033[H\033[2J", input, n) == 0) { - if (write(STDOUT_FILENO, input, n) == -1) - die("write:"); + if (strncmp("\033[H\033[2J", input, n) == 0) continue; - } /* iterate over the input buffer */ for (char *c = input; n-- > 0; c++) { /* don't save lines from alternative screen */ - if (!isaltscreen(*c)) { - if (*c == '\r') { - addline(buf, pos); - memset(buf, 0, size); - pos = 0; - } - buf[pos++] = *c; - if (pos == size) { - size *= 2; - buf = earealloc(buf, size); - } - } + if (isaltscreen(*c)) + continue; - if (write(STDOUT_FILENO, c, 1) == -1) - die("write:"); + if (*c == '\r') { + addline(buf, pos); + memset(buf, 0, size); + pos = 0; + } + buf[pos++] = *c; + if (pos == size) { + size *= 2; + buf = earealloc(buf, size); + } } } }