commit aa787b489c6c40b38d6349eb5ff29c42231ce989
parent 3cb1da6eee93e7ff11ecccdfa0cd2aeab95675f0
Author: Christos Margiolis <christos@margiolis.net>
Date: Tue, 10 May 2022 16:22:03 +0300
fix first character eating when changing line
Diffstat:
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/nfy.1 b/nfy.1
@@ -14,9 +14,8 @@ reads input from stdin (only), creates a temporary popup window and \
displays it. Configuration is done by editing the 'config.h' file in the \
source code.
.Pp
-.Nm
-has non-blocking behaviour, meaning that commands coming after it can execute \
-normally without them having to wait for
+It has non-blocking behaviour, meaning that commands coming after it can \
+execute normally without them having to wait for
.Nm
to finish first.
This is especially useful inside scripts.
diff --git a/nfy.c b/nfy.c
@@ -151,7 +151,11 @@ main(int argc, char *argv[])
if ((lines = malloc(sizeof(struct line))) == NULL)
err(1, "malloc");
while (read(STDIN_FILENO, &ch, 1) > 0) {
+ buf[len++] = ch;
if (ch == '\n' || len == MAXLEN) {
+ /* FIXME: is this stupid? */
+ if (ch == '\n')
+ len--;
buf[len] = '\0';
if ((lines = realloc(lines,
(nlines + 1) * sizeof(struct line))) == NULL)
@@ -166,8 +170,7 @@ main(int argc, char *argv[])
w = gi.width;
nlines++;
len = 0;
- } else
- buf[len++] = ch;
+ }
}
w += padding * 2;
h = (nlines - 1) * linespace + nlines * th + 2 * padding;