Krolyxon
Commit b4268fb

Branches

Refs →

nsxivb4268fb

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
Author
NRK
Date
2022-05-09 19:06 +0600
Committer
N-R-K · 2022-05-19 11:44 +0000
Parent
f255e1c
Commit
b4268fbf38d1f8433c73999466e116e68c7f81e7

+6 −25

1 file changed

  1. M main.c +6 −25
M main.c View
@@ -73,7 +73,6 @@ static bool resized = false;
7373 static struct {
7474 extcmd_t f, ft;
7575 int fd;
76− unsigned int i, lastsep;
7776 pid_t pid;
7877 } info;
7978
@@ -296,7 +295,6 @@ void open_info(void)
296295 if (pfd.readfd >= 0) {
297296 fcntl(pfd.readfd, F_SETFL, O_NONBLOCK);
298297 info.fd = pfd.readfd;
299− info.i = info.lastsep = 0;
300298 info.pid = pfd.pid;
301299 }
302300 }
@@ -304,32 +302,15 @@ void open_info(void)
304302 static void read_info(void)
305303 {
306304 ssize_t i, n;
307− char buf[BAR_L_LEN];
308305
309− while (true) {
310− n = read(info.fd, buf, sizeof(buf));
311− if (n < 0 && errno == EAGAIN)
312− return;
313− else if (n == 0)
314− goto end;
315− for (i = 0; i < n; i++) {
316− if (buf[i] == '\n') {
317− if (info.lastsep == 0) {
318− win.bar.l.buf[info.i++] = ' ';
319− info.lastsep = 1;
320− }
321− } else {
322− win.bar.l.buf[info.i++] = buf[i];
323− info.lastsep = 0;
324− }
325− if (info.i + 1 == win.bar.l.size)
326− goto end;
306+ if ((n = read(info.fd, win.bar.l.buf, win.bar.l.size - 1)) > 0) {
307+ win.bar.l.buf[n] = '\0';
308+ for (i = 0; i < n; ++i) {
309+ if (win.bar.l.buf[i] == '\n')
310+ win.bar.l.buf[i] = ' ';
327311 }
312+ win_draw(&win);
328313 }
329−end:
330− info.i -= info.lastsep;
331− win.bar.l.buf[info.i] = '\0';
332− win_draw(&win);
333314 close_info();
334315 }
335316