Disable redbean repl on windows

This commit is contained in:
Justine Tunney 2022-04-16 23:46:16 -07:00
parent 4a6a34db83
commit 80308079ec
2 changed files with 30 additions and 23 deletions

View file

@ -700,12 +700,14 @@ static void LoadSyms(void) {
static int DrainInput(int fd) {
char buf[32];
struct pollfd fds[1];
for (;;) {
fds[0].fd = fd;
fds[0].events = POLLIN;
if (poll(fds, ARRAYLEN(fds), 0) == -1) return -1;
if (!(fds[0].revents & POLLIN)) break;
if (read(fd, buf, sizeof(buf)) == -1) return -1;
if (!IsWindows()) {
for (;;) {
fds[0].fd = fd;
fds[0].events = POLLIN;
if (poll(fds, ARRAYLEN(fds), 0) == -1) return -1;
if (!(fds[0].revents & POLLIN)) break;
if (read(fd, buf, sizeof(buf)) == -1) return -1;
}
}
return 0;
}
@ -1928,19 +1930,21 @@ static int OnPtyFdPoll(struct pollfd *fds, size_t nfds, int ms) {
}
p2.fd = fds[i].fd;
p2.events = fds[i].events;
switch (poll(&p2, 1, ms)) {
case -1:
re = POLLERR;
++t;
break;
case 0:
break;
case 1:
re = p2.revents;
++t;
break;
default:
unreachable;
if (!IsWindows()) {
switch (poll(&p2, 1, ms)) {
case -1:
re = POLLERR;
++t;
break;
case 0:
break;
case 1:
re = p2.revents;
++t;
break;
default:
unreachable;
}
}
}
}
@ -2602,7 +2606,11 @@ static bool HasPendingKeyboard(void) {
}
static void Sleep(int ms) {
poll((struct pollfd[]){{ttyin, POLLIN}}, 1, ms);
if (IsWindows()) {
usleep(ms * 1000L);
} else {
poll((struct pollfd[]){{ttyin, POLLIN}}, 1, ms);
}
}
static void OnMouseWheelUp(struct Panel *p, int y, int x) {

View file

@ -6830,7 +6830,6 @@ static int EventLoop(int fd, int ms) {
int rc;
long double t;
rc = -1;
polls[0].fd = 0;
while (!terminated) {
errno = 0;
if (zombied) {
@ -6848,13 +6847,13 @@ static int EventLoop(int fd, int ms) {
break; // return control to linenoise
}
}
polls[0].fd = -1;
return rc;
}
static void ReplEventLoop(void) {
int status;
lua_State *L = GL;
polls[0].fd = 0;
__nomultics = 2;
__replmode = true;
lua_initrepl("redbean");
@ -7096,7 +7095,7 @@ void RedBean(int argc, char *argv[]) {
#ifdef STATIC
EventLoop();
#else
if (isatty(0)) {
if (!IsWindows() && isatty(0)) {
ReplEventLoop();
} else {
EventLoop(-1, HEARTBEAT);