feat: update to new render-request API

master
LordMZTE 2 months ago
parent e2884c646a
commit dae1092273
Signed by: LordMZTE
GPG Key ID: B64802DC33A64FF6

@ -5,14 +5,6 @@ pkgs:
license: GPL-3.0
root: src/main.zig
deps:
# zellzig dependency for development
zellzig:
local: ..
root: src/main.zig
# use this for actual plugins:
#zellzig:
# git:
# url: "https://mzte.de/git/LordMZTE/zellzig.git"
# ref: master
# root: src/main.zig

@ -14,6 +14,9 @@ comptime {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var mode: ?zz.types.InputMode = null;
// the zellij version the plugin is written for
pub const zellij_version = "0.34.0";
// called on startup
pub fn init() void {
// This is required to make zellij close once everything but our plugin is gone.
@ -24,14 +27,19 @@ pub fn init() void {
}
// called on every event
pub fn update() void {
var ev = zz.getEvent(gpa.allocator()) catch return;
// return true to indicate that the plugin should be rendered
pub fn update() bool {
var ev = zz.getEvent(gpa.allocator()) catch return false;
defer ev.deinit();
switch (ev.data) {
.ModeUpdate => |mode_info| mode = mode_info.mode,
.ModeUpdate => |mode_info| {
mode = mode_info.mode;
return true;
},
else => {},
}
return false;
}
// called to draw the UI

@ -26,13 +26,17 @@ test {
/// zz.createPlugin(@This());
/// }
///
/// pub const zellij_version = "0.33.0";
/// pub const zellij_version = "0.34.0";
///
/// pub fn init() void {}
/// pub fn update(event: zz.Event) void {
/// pub fn update(event: zz.Event) bool {
/// var event = zz.getEvent(gpa.allocator()) catch return;
/// defer event.deinit();
///
/// // use event
///
/// // return true to request render
/// return true;
/// }
/// pub fn render(rows: i32, cols: i32) void {}
/// ```
@ -40,7 +44,7 @@ pub fn createPlugin(comptime Plugin: type) void {
if (@TypeOf(Plugin.init) != fn () void)
@compileError("Function 'init' has invalid signature!");
if (@TypeOf(Plugin.update) != fn () void)
if (@TypeOf(Plugin.update) != fn () bool)
@compileError("Function 'update' has invalid signature!");
if (@TypeOf(Plugin.render) != fn (i32, i32) void)
@ -55,8 +59,8 @@ pub fn createPlugin(comptime Plugin: type) void {
Plugin.render(rows, cols);
}
export fn update() void {
Plugin.update();
export fn update() bool {
return Plugin.update();
}
export fn plugin_version() void {

Loading…
Cancel
Save