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) { static int DrainInput(int fd) {
char buf[32]; char buf[32];
struct pollfd fds[1]; struct pollfd fds[1];
for (;;) { if (!IsWindows()) {
fds[0].fd = fd; for (;;) {
fds[0].events = POLLIN; fds[0].fd = fd;
if (poll(fds, ARRAYLEN(fds), 0) == -1) return -1; fds[0].events = POLLIN;
if (!(fds[0].revents & POLLIN)) break; if (poll(fds, ARRAYLEN(fds), 0) == -1) return -1;
if (read(fd, buf, sizeof(buf)) == -1) return -1; if (!(fds[0].revents & POLLIN)) break;
if (read(fd, buf, sizeof(buf)) == -1) return -1;
}
} }
return 0; return 0;
} }
@ -1928,19 +1930,21 @@ static int OnPtyFdPoll(struct pollfd *fds, size_t nfds, int ms) {
} }
p2.fd = fds[i].fd; p2.fd = fds[i].fd;
p2.events = fds[i].events; p2.events = fds[i].events;
switch (poll(&p2, 1, ms)) { if (!IsWindows()) {
case -1: switch (poll(&p2, 1, ms)) {
re = POLLERR; case -1:
++t; re = POLLERR;
break; ++t;
case 0: break;
break; case 0:
case 1: break;
re = p2.revents; case 1:
++t; re = p2.revents;
break; ++t;
default: break;
unreachable; default:
unreachable;
}
} }
} }
} }
@ -2602,7 +2606,11 @@ static bool HasPendingKeyboard(void) {
} }
static void Sleep(int ms) { 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) { 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; int rc;
long double t; long double t;
rc = -1; rc = -1;
polls[0].fd = 0;
while (!terminated) { while (!terminated) {
errno = 0; errno = 0;
if (zombied) { if (zombied) {
@ -6848,13 +6847,13 @@ static int EventLoop(int fd, int ms) {
break; // return control to linenoise break; // return control to linenoise
} }
} }
polls[0].fd = -1;
return rc; return rc;
} }
static void ReplEventLoop(void) { static void ReplEventLoop(void) {
int status; int status;
lua_State *L = GL; lua_State *L = GL;
polls[0].fd = 0;
__nomultics = 2; __nomultics = 2;
__replmode = true; __replmode = true;
lua_initrepl("redbean"); lua_initrepl("redbean");
@ -7096,7 +7095,7 @@ void RedBean(int argc, char *argv[]) {
#ifdef STATIC #ifdef STATIC
EventLoop(); EventLoop();
#else #else
if (isatty(0)) { if (!IsWindows() && isatty(0)) {
ReplEventLoop(); ReplEventLoop();
} else { } else {
EventLoop(-1, HEARTBEAT); EventLoop(-1, HEARTBEAT);