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
+6 −25
1 file changed
- M main.c +6 −25
| @@ -73,7 +73,6 @@ static bool resized = false; | |||
| 73 | 73 | static struct { | |
| 74 | 74 | extcmd_t f, ft; | |
| 75 | 75 | int fd; | |
| 76 | − | unsigned int i, lastsep; | |
| 77 | 76 | pid_t pid; | |
| 78 | 77 | } info; | |
| 79 | 78 | ||
| @@ -296,7 +295,6 @@ void open_info(void) | |||
| 296 | 295 | if (pfd.readfd >= 0) { | |
| 297 | 296 | fcntl(pfd.readfd, F_SETFL, O_NONBLOCK); | |
| 298 | 297 | info.fd = pfd.readfd; | |
| 299 | − | info.i = info.lastsep = 0; | |
| 300 | 298 | info.pid = pfd.pid; | |
| 301 | 299 | } | |
| 302 | 300 | } | |
| @@ -304,32 +302,15 @@ void open_info(void) | |||
| 304 | 302 | static void read_info(void) | |
| 305 | 303 | { | |
| 306 | 304 | ssize_t i, n; | |
| 307 | − | char buf[BAR_L_LEN]; | |
| 308 | 305 | ||
| 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] = ' '; | |
| 327 | 311 | } | |
| 312 | + | win_draw(&win); | |
| 328 | 313 | } | |
| 329 | − | end: | |
| 330 | − | info.i -= info.lastsep; | |
| 331 | − | win.bar.l.buf[info.i] = '\0'; | |
| 332 | − | win_draw(&win); | |
| 333 | 314 | close_info(); | |
| 334 | 315 | } | |
| 335 | 316 | ||