From dae109227370c9ed7f34feff575e103424525480 Mon Sep 17 00:00:00 2001 From: LordMZTE Date: Tue, 29 Nov 2022 15:59:27 +0100 Subject: [PATCH] feat: update to new render-request API --- example/gyro.zzz | 8 -------- example/src/main.zig | 14 +++++++++++--- src/main.zig | 14 +++++++++----- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/example/gyro.zzz b/example/gyro.zzz index d4b33f6..edcf634 100644 --- a/example/gyro.zzz +++ b/example/gyro.zzz @@ -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 diff --git a/example/src/main.zig b/example/src/main.zig index eff3e88..90f3c43 100644 --- a/example/src/main.zig +++ b/example/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 diff --git a/src/main.zig b/src/main.zig index 3678e28..81f5fb5 100644 --- a/src/main.zig +++ b/src/main.zig @@ -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 {