aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2022-05-09 19:06:24 +0600
committerN-R-K <nrk@disroot.org>2022-05-19 11:44:30 +0000
commitb4268fbf38d1f8433c73999466e116e68c7f81e7 (patch)
tree958dd78c0376f2a9ef79014634dff291f4b5895b
parentf255e1cc1217ee7497436909a8a9b8dbf8fd270e (diff)
fix: broken statusbar after key-handler cancellation
to reproduce: 1. have an image-info script 2. invoke the key-handler 3. cancle invocation by pressing `escape` at this point, the statusbar ends up being empty. the regression seems to be caused by 6922d5d (changing select to poll), unsure why that is. in any case, this simplifies read_info quite a bit and solves the regression as well. in short: * read straight into the statusbar buffer * if read succeeds, make sure buffer is null terminated and replace any newline with space * close the script
-rw-r--r--main.c31
1 files changed, 6 insertions, 25 deletions
diff --git a/main.c b/main.c
index 316c00e..7c27f96 100644
--- a/main.c
+++ b/main.c
@@ -73,7 +73,6 @@ static bool resized = false;
static struct {
extcmd_t f, ft;
int fd;
- unsigned int i, lastsep;
pid_t pid;
} info;
@@ -296,7 +295,6 @@ void open_info(void)
if (pfd.readfd >= 0) {
fcntl(pfd.readfd, F_SETFL, O_NONBLOCK);
info.fd = pfd.readfd;
- info.i = info.lastsep = 0;
info.pid = pfd.pid;
}
}
@@ -304,32 +302,15 @@ void open_info(void)
static void read_info(void)
{
ssize_t i, n;
- char buf[BAR_L_LEN];
- while (true) {
- n = read(info.fd, buf, sizeof(buf));
- if (n < 0 && errno == EAGAIN)
- return;
- else if (n == 0)
- goto end;
- for (i = 0; i < n; i++) {
- if (buf[i] == '\n') {
- if (info.lastsep == 0) {
- win.bar.l.buf[info.i++] = ' ';
- info.lastsep = 1;
- }
- } else {
- win.bar.l.buf[info.i++] = buf[i];
- info.lastsep = 0;
- }
- if (info.i + 1 == win.bar.l.size)
- goto end;
+ if ((n = read(info.fd, win.bar.l.buf, win.bar.l.size - 1)) > 0) {
+ win.bar.l.buf[n] = '\0';
+ for (i = 0; i < n; ++i) {
+ if (win.bar.l.buf[i] == '\n')
+ win.bar.l.buf[i] = ' ';
}
+ win_draw(&win);
}
-end:
- info.i -= info.lastsep;
- win.bar.l.buf[info.i] = '\0';
- win_draw(&win);
close_info();
}