๐จ
36+ Widgets
Complete widget library including forms, navigation, feedback, and data display components
Build beautiful, performant terminal applications with Zig
const tui = @import("tui");
pub fn main() !void {
var app = try tui.App.init(.{});
defer app.deinit();
var widget = MyWidget{};
try app.setRoot(&widget);
try app.run();
}
const MyWidget = struct {
count: i32 = 0,
pub fn render(self: *MyWidget, ctx: *tui.RenderContext) void {
var screen = ctx.getSubScreen();
var buf: [32]u8 = undefined;
const text = std.fmt.bufPrint(&buf, "Count: {d}", .{self.count}) catch "?";
screen.moveCursor(10, 10);
screen.setStyle(tui.Style.default.bold().setFg(tui.Color.cyan));
screen.putString(text);
}
pub fn handleEvent(self: *MyWidget, event: tui.Event) tui.EventResult {
if (event == .key) {
switch (event.key.key) {
.up => {
self.count += 1;
return .needs_redraw;
},
.down => {
self.count -= 1;
return .needs_redraw;
},
else => {},
}
}
return .ignored;
}
};zig fetch --save git+https://github.com/muhammad-fiaz/tui.zig.gitAdd to your build.zig:
const tui_dep = b.dependency("tui", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("tui", tui_dep.module("tui"));MIT License - see LICENSE