57 lines
1.6 KiB
Zig
57 lines
1.6 KiB
Zig
const std = @import("std");
|
|
const zz = @import("zellzig");
|
|
|
|
comptime {
|
|
// This function creates all the exports needed by zellij plugins.
|
|
// As a paremeter, you should pass the struct that contains the
|
|
// `init`, `update` and `render` functions. It is recommended
|
|
// to put these functions in your root file, and pass the root
|
|
// struct by using `@This()`.
|
|
zz.createPlugin(@This());
|
|
}
|
|
|
|
// assign out allocator to make sure it doesn't get free'd once init returns
|
|
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.
|
|
zz.api.setSelectable(false);
|
|
|
|
// Make sure we get events.
|
|
zz.api.subscribe(&[_]zz.types.EventType{.ModeUpdate}) catch unreachable;
|
|
}
|
|
|
|
// called on every event
|
|
// 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;
|
|
return true;
|
|
},
|
|
else => {},
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// called to draw the UI
|
|
pub fn render(rows: i32, cols: i32) void {
|
|
_ = rows;
|
|
_ = cols;
|
|
|
|
if (mode) |m| {
|
|
var out = std.io.getStdOut();
|
|
var writer = out.writer();
|
|
writer.writeAll("Super sophisticated status bar: ") catch {};
|
|
writer.writeAll(@tagName(m)) catch {};
|
|
}
|
|
}
|