From cc56038b0574b4966dbf4c6dd2328adb5f21b41a Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Sat, 27 Feb 2021 14:59:26 -0800 Subject: [PATCH] Fix memzoom on Windows Right now we can't call poll() on file and fifos on Windows. So we work around that by simply blocking on keyboard input. This is OK because on Windows we can't use /proc/*/mem for realtime monitoring, so there's no reason not to block. See #65 --- libc/runtime/winmain.greg.c | 1 + tool/viz/memzoom.c | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/libc/runtime/winmain.greg.c b/libc/runtime/winmain.greg.c index e8287dc2..d3e9d2d3 100644 --- a/libc/runtime/winmain.greg.c +++ b/libc/runtime/winmain.greg.c @@ -97,6 +97,7 @@ static noasan textwindows wontreturn void WinMainNew(void) { SetConsoleCP(kNtCpUtf8); SetConsoleOutputCP(kNtCpUtf8); inhand = GetStdHandle(pushpop(kNtStdInputHandle)); + SetEnvironmentVariable(u"TERM", u"xterm-truecolor"); GetConsoleMode(inhand, &__ntconsolemode); SetConsoleMode(inhand, kNtEnableProcessedInput | kNtEnableLineInput | kNtEnableEchoInput | kNtEnableMouseInput | diff --git a/tool/viz/memzoom.c b/tool/viz/memzoom.c index d2da49a1..a4a84a17 100644 --- a/tool/viz/memzoom.c +++ b/tool/viz/memzoom.c @@ -318,6 +318,7 @@ static void PreventBufferbloat(void) { static bool HasPendingInput(void) { struct pollfd fds[1]; + if (IsWindows()) return true; /* XXX */ fds[0].fd = 0; fds[0].events = POLLIN; fds[0].revents = 0; @@ -841,16 +842,19 @@ static void RangesZoom(void) { } static void MemZoom(void) { + bool ok; + ok = false; do { if (action & RESIZED) { GetTtySize(); SetupCanvas(); action &= ~RESIZED; } - if (HasPendingInput()) { + if (ok && HasPendingInput()) { ReadKeyboard(); - continue; + if (!IsWindows()) continue; /* XXX */ } + ok = true; if (pid) { RangesZoom(); } else {