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
This commit is contained in:
parent
f255e1cc12
commit
b4268fbf38
31
main.c
31
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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user