From 43ea14e263abaaf95c3c27953bc60141c049cdcd Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 19 Jan 2024 12:24:02 -0600 Subject: [PATCH] queue: check for fields before posting events This allows users of the lib to not worry about having the fields on their enum Signed-off-by: Tim Culverhouse --- src/Tty.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Tty.zig b/src/Tty.zig index 5330cbc..e8996c1 100644 --- a/src/Tty.zig +++ b/src/Tty.zig @@ -60,7 +60,9 @@ pub fn run( // get our initial winsize const winsize = try getWinsize(self.fd); - vx.postEvent(.{ .winsize = winsize }); + if (@hasField(EventType, "winsize")) { + vx.postEvent(.{ .winsize = winsize }); + } // assign the write end of the pipe to our quit_fd self.quit_fd = pipe[1]; @@ -94,7 +96,9 @@ pub fn run( const ws = getWinsize(fd) catch { return; }; - vx_winch.postEvent(.{ .winsize = ws }); + if (@hasField(EventType, "winsize")) { + vx_winch.postEvent(.{ .winsize = ws }); + } } }; try WinchHandler.init(vx, self.fd); @@ -157,7 +161,9 @@ pub fn run( else => Key{ .codepoint = b }, }; if (key) |k| { - vx.postEvent(.{ .key_press = k }); + if (@hasField(EventType, "key_press")) { + vx.postEvent(.{ .key_press = k }); + } } }, .escape => state = .ground,