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:
parent
811fbdd2cb
commit
43ea14e263
1 changed files with 9 additions and 3 deletions
12
src/Tty.zig
12
src/Tty.zig
|
@ -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);
|
||||||
vx.postEvent(.{ .winsize = winsize });
|
if (@hasField(EventType, "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,7 +96,9 @@ pub fn run(
|
||||||
const ws = getWinsize(fd) catch {
|
const ws = getWinsize(fd) catch {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
vx_winch.postEvent(.{ .winsize = ws });
|
if (@hasField(EventType, "winsize")) {
|
||||||
|
vx_winch.postEvent(.{ .winsize = ws });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
try WinchHandler.init(vx, self.fd);
|
try WinchHandler.init(vx, self.fd);
|
||||||
|
@ -157,7 +161,9 @@ pub fn run(
|
||||||
else => Key{ .codepoint = b },
|
else => Key{ .codepoint = b },
|
||||||
};
|
};
|
||||||
if (key) |k| {
|
if (key) |k| {
|
||||||
vx.postEvent(.{ .key_press = k });
|
if (@hasField(EventType, "key_press")) {
|
||||||
|
vx.postEvent(.{ .key_press = k });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.escape => state = .ground,
|
.escape => state = .ground,
|
||||||
|
|
Loading…
Reference in a new issue