Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed multiline input #186

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions lemonbar.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ctype.h>
#include <signal.h>
#include <poll.h>
#include <fcntl.h>
#include <getopt.h>
#include <unistd.h>
#include <errno.h>
Expand Down Expand Up @@ -1344,6 +1345,9 @@ main (int argc, char **argv)
// Get the fd to Xserver
pollin[1].fd = xcb_get_file_descriptor(c);

// Prevent fgets to block
fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);

for (;;) {
bool redraw = false;

Expand All @@ -1357,9 +1361,9 @@ main (int argc, char **argv)
else break; // ...bail out
}
if (pollin[0].revents & POLLIN) { // New input, process it
if (fgets(input, sizeof(input), stdin) == NULL)
break; // EOF received

input[0] = '\0';
while (fgets(input, sizeof(input), stdin) != NULL)
; // Drain the buffer, the last line is actually used
parse(input);
redraw = true;
}
Expand Down