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 <tim@timculverhouse.com>
This commit is contained in:
Tim Culverhouse 2024-01-19 12:24:02 -06:00
parent 811fbdd2cb
commit 43ea14e263

View file

@ -60,7 +60,9 @@ pub fn run(
// get our initial winsize // get our initial winsize
const winsize = try getWinsize(self.fd); const winsize = try getWinsize(self.fd);
if (@hasField(EventType, "winsize")) {
vx.postEvent(.{ .winsize = winsize }); vx.postEvent(.{ .winsize = winsize });
}
// assign the write end of the pipe to our quit_fd // assign the write end of the pipe to our quit_fd
self.quit_fd = pipe[1]; self.quit_fd = pipe[1];
@ -94,8 +96,10 @@ pub fn run(
const ws = getWinsize(fd) catch { const ws = getWinsize(fd) catch {
return; return;
}; };
if (@hasField(EventType, "winsize")) {
vx_winch.postEvent(.{ .winsize = ws }); vx_winch.postEvent(.{ .winsize = ws });
} }
}
}; };
try WinchHandler.init(vx, self.fd); try WinchHandler.init(vx, self.fd);
@ -157,8 +161,10 @@ pub fn run(
else => Key{ .codepoint = b }, else => Key{ .codepoint = b },
}; };
if (key) |k| { if (key) |k| {
if (@hasField(EventType, "key_press")) {
vx.postEvent(.{ .key_press = k }); vx.postEvent(.{ .key_press = k });
} }
}
}, },
.escape => state = .ground, .escape => state = .ground,
else => {}, else => {},