From 5893ab15fa818399f944e349a3515f48f34480c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20M=C3=A9sz=C3=A1ros=20=28Laptop=29?= Date: Tue, 17 Feb 2026 14:04:18 +0100 Subject: [PATCH] fix(windows): use WaitForSingleObject to make readInput non-blocking --- src/terminal/platform/windows.zig | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/terminal/platform/windows.zig b/src/terminal/platform/windows.zig index 23a68a0..77127c6 100644 --- a/src/terminal/platform/windows.zig +++ b/src/terminal/platform/windows.zig @@ -181,10 +181,21 @@ pub fn disableMouse(state: *State, writer: anytype) !void { /// Read available input (Windows uses std.io) pub fn readInput(state: *State, buffer: []u8, timeout_ms: i32) !usize { - _ = state; - _ = timeout_ms; - // On Windows, we use the standard reader which handles VT input - const stdin = std.fs.File.stdin(); + if (state.stdin_handle == windows.INVALID_HANDLE_VALUE) return 0; + + // Match POSIX behavior: wait up to timeout_ms for input, then return 0. + const wait_ms: windows.DWORD = if (timeout_ms < 0) + windows.INFINITE + else + @intCast(timeout_ms); + + windows.WaitForSingleObject(state.stdin_handle, wait_ms) catch |err| switch (err) { + error.WaitTimeOut => return 0, + else => return 0, + }; + + // Read from the configured stdin handle after it is signaled as readable. + const stdin: std.fs.File = .{ .handle = state.stdin_handle }; return stdin.read(buffer) catch 0; }