From b4268fbf38d1f8433c73999466e116e68c7f81e7 Mon Sep 17 00:00:00 2001 From: NRK Date: Mon, 9 May 2022 19:06:24 +0600 Subject: 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 --- main.c | 31 ++++++------------------------- 1 file 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(); } -- cgit v1.2.3