Zig NEWS

Andrei Karpovskii
Andrei Karpovskii

Posted on

Introducing Tuile - a Text User Interface library for Zig

Tuile is a Text User Interface library for Zig. It aims to be simple yet powerful enough to allow you to build rich user interfaces for your programs!

Features:

  • Declarative API
  • Common widgets included
  • Customizable themes
  • Colors, text styles, and more

Let’s see an example:

const tuile = @import("tuile");

pub fn stop(tui: ?*tuile.Tuile) void {
    tui.?.stop();
}

pub fn main() !void {
    var tui = try tuile.Tuile.init(.{});
    defer tui.deinit();

    try tui.add(
        tuile.block(
            .{
                .border = tuile.Border.all(),
                .border_type = .rounded,
                .layout = .{ .flex = 1 },
            },
            tuile.vertical(.{}, .{
                tuile.label(.{ .text = "Hello World!" }),
                tuile.button(.{
                    .text = "Quit",
                    .on_press = .{
                        .cb = @ptrCast(&stop),
                        .payload = &tui,
                    },
                }),
            }),
        ),
    );

    try tui.run();
}
Enter fullscreen mode Exit fullscreen mode

A screenshot displaying "Hello World!" label and a "Quit" button inside a block with rounded solid borders, centered

Add it to your project

  1. Add dependency to your build.zig.zon:
zig fetch --save https://github.com/akarpovskii/tuile/archive/refs/tags/v0.1.0.tar.gz
Enter fullscreen mode Exit fullscreen mode
  1. Import Tuile in build.zig and link ncurses:
const tuile = b.dependency("tuile", .{});
exe.root_module.addImport("tuile", tuile.module("tuile"));
exe.linkLibC();
exe.linkSystemLibrary("ncurses");
Enter fullscreen mode Exit fullscreen mode

Visit Tuile's GitHub repository to explore examples and contribute to the library.

Oldest comments (0)