Skip to content

Commit fed2c87

Browse files
committed
TerminalTheme (macOS): fix hanging on GNU screen 5.0
1 parent b7fcd7f commit fed2c87

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/common/io/io_unix.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
44

55
#include <fcntl.h>
66
#include <termios.h>
7-
#include <poll.h>
87
#include <dirent.h>
98
#include <errno.h>
9+
#ifndef __APPLE__
10+
#include <poll.h>
11+
#else
12+
#include <sys/select.h>
13+
#endif
1014

1115
#if FF_HAVE_WORDEXP
1216
#include <wordexp.h>
@@ -161,8 +165,20 @@ const char* ffGetTerminalResponse(const char* request, const char* format, ...)
161165
ffWriteFDData(ftty, strlen(request), request);
162166

163167
//Give the terminal some time to respond
168+
#ifndef __APPLE__
164169
if(poll(&(struct pollfd) { .fd = ftty, .events = POLLIN }, 1, FF_IO_TERM_RESP_WAIT_MS) <= 0)
165-
return "poll() timeout or failed";
170+
return "poll(/dev/tty) timeout or failed";
171+
#else
172+
{
173+
// On macOS, poll(/dev/tty) always returns immediately
174+
// See also https://nathancraddock.com/blog/macos-dev-tty-polling/
175+
fd_set rd;
176+
FD_ZERO(&rd);
177+
FD_SET(ftty, &rd);
178+
if(select(ftty + 1, &rd, NULL, NULL, &(struct timeval) { .tv_sec = FF_IO_TERM_RESP_WAIT_MS / 1000, .tv_usec = (FF_IO_TERM_RESP_WAIT_MS % 1000) * 1000 }) <= 0)
179+
return "select(/dev/tty) timeout or failed";
180+
}
181+
#endif
166182

167183
char buffer[512];
168184
ssize_t bytesRead = read(ftty, buffer, sizeof(buffer) - 1);

0 commit comments

Comments
 (0)