-
Notifications
You must be signed in to change notification settings - Fork 2
Closed
Description
On Windows 11 the tick functionality does not work unless a key is pressed, including the initial command returned from the model's init() function.
I debugged the problem down to the line 188 stdin.read(buffer) in src/terminal/platform/windows.zig but I don't know how to fix it.
Tested on Zig 0.15.2, old cmd, the new terminal and powershell
minimal test code
The counter should go up every 500 ms on its own, but only does so when a key is held down
const std = @import("std");
const zz = @import("zigzag");
const Model = struct {
count: i32,
pub const Msg = union(enum) {
key: zz.KeyEvent,
tick: zz.msg.Tick,
};
pub fn init(self: *Model, _: *zz.Context) zz.Cmd(Msg) {
self.* = .{ .count = 0 };
return zz.Cmd(Msg).tickMs(500);
}
pub fn update(self: *Model, msg: Msg, _: *zz.Context) zz.Cmd(Msg) {
switch (msg) {
.tick => {
self.count += 1;
return zz.Cmd(Msg).tickMs(500);
},
.key => |k| switch (k.key) {
.char => |c| if (c == 'q') return .quit,
else => {},
},
}
return .none;
}
pub fn view(self: *const Model, ctx: *const zz.Context) []const u8 {
const style = (zz.Style{}).bold(true).fg(zz.Color.cyan());
const text = std.fmt.allocPrint(ctx.allocator, "Count: {d}\n\nPress q to quit", .{self.count}) catch "Error";
return style.render(ctx.allocator, text) catch text;
}
};
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
var program = try zz.Program(Model).init(gpa.allocator());
defer program.deinit();
try program.run();
}The library works very nicely apart from this problem and even on Termux on android!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels