[hackers] [scroll] handle carriage0-return correctly || Jan Klemkow
commit f0e76e5f8c92a00075002087396a37ee94901d34
Author: Jan Klemkow <j.klemkow_AT_wemelug.de>
AuthorDate: Sat May 16 23:09:11 2020 +0200
Commit: Jan Klemkow <j.klemkow_AT_wemelug.de>
CommitDate: Sat May 16 23:10:14 2020 +0200
handle carriage0-return correctly
diff --git a/scroll.c b/scroll.c
index 6cb192a..2361046 100644
--- a/scroll.c
+++ b/scroll.c
_AT_@ -179,8 +179,6 @@ skipesc(char c)
switch (state) {
case CHAR:
- if (c == '\r')
- return true;
if (c == '\033')
state = BREK;
break;
_AT_@ -493,7 +491,7 @@ main(int argc, char *argv[])
if (tcsetattr(STDIN_FILENO, TCSANOW, &new) == -1)
die("tcsetattr:");
- size_t size = BUFSIZ, pos = 0;
+ size_t size = BUFSIZ, len = 0, pos = 0;
char *buf = calloc(size, sizeof *buf);
if (buf == NULL)
die("calloc:");
_AT_@ -536,7 +534,7 @@ main(int argc, char *argv[])
if (rules[i].event == SCROLL_UP)
scrollup(rules[i].lines);
if (rules[i].event == SCROLL_DOWN)
- scrolldown(buf, pos,
+ scrolldown(buf, len,
rules[i].lines);
goto out;
}
_AT_@ -546,7 +544,7 @@ main(int argc, char *argv[])
die("write:");
if (bottom != TAILQ_FIRST(&head))
- jumpdown(buf, pos);
+ jumpdown(buf, len);
}
out:
if (pfd[1].revents & POLLIN) {
_AT_@ -572,7 +570,7 @@ main(int argc, char *argv[])
continue;
if (*c == '\n') {
- addline(buf, pos);
+ addline(buf, len);
/* only advance bottom if scroll is */
/* at the end of the scroll back */
if (bottom == NULL ||
_AT_@ -581,11 +579,16 @@ main(int argc, char *argv[])
bottom = TAILQ_FIRST(&head);
memset(buf, 0, size);
- pos = 0;
+ len = pos = 0;
buf[pos++] = '\r';
+ } else if (*c == '\r') {
+ pos = 0;
+ continue;
}
buf[pos++] = *c;
- if (pos == size) {
+ if (pos > len)
+ len = pos;
+ if (len == size) {
size *= 2;
buf = earealloc(buf, size);
}
Received on Sat May 16 2020 - 23:10:19 CEST
This archive was generated by hypermail 2.3.0
: Sat May 16 2020 - 23:12:36 CEST