Skip to content

TUI.zigModern Terminal UI Framework

Build beautiful, performant terminal applications with Zig

TUI.zig

Quick Example โ€‹

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;
    }
};

Features at a Glance โ€‹

Complete Widget Library โ€‹

  • Forms: InputField, TextArea, Checkbox, RadioGroup, Switch, Slider
  • Navigation: Navbar, Sidebar, Breadcrumb, Tabs, Menu, Pagination
  • Feedback: Alert, Toast, Modal, Progress, Spinner, Skeleton
  • Display: Text, Badge, Card, Table, ListView, TreeView, Image
  • Layout: Grid, Accordion, SplitView, ScrollView, Separator

Advanced Animation System โ€‹

  • 30+ easing functions (Linear, Quad, Cubic, Sine, Expo, Circ, Back, Elastic, Bounce)
  • Generic Animation<T> for any type
  • Loop and alternate modes
  • Animation groups and timers

Flexible Layout Engine โ€‹

  • FlexRow/FlexColumn for responsive layouts
  • Grid for structured designs
  • Stack for overlays
  • Absolute positioning
  • Box model with padding/margin

Rich Styling โ€‹

  • True color (24-bit RGB)
  • 256-color palette
  • 16 ANSI colors
  • Bold, italic, underline, dim, reverse
  • 6 built-in themes

Why TUI.zig? โ€‹

  • Production Ready: 36 widgets, comprehensive features, full test coverage
  • High Performance: Diff-based rendering, minimal allocations, 60 FPS
  • Developer Friendly: Simple API, type-safe, composable
  • Cross-Platform: Linux, macOS, Windows support
  • Zero Dependencies: Pure Zig implementation
  • Well Documented: Complete guides and API reference

Installation โ€‹

bash
zig fetch --save git+https://github.com/muhammad-fiaz/tui.zig.git

Add to your build.zig:

zig
const tui_dep = b.dependency("tui", .{
    .target = target,
    .optimize = optimize,
});
exe.root_module.addImport("tui", tui_dep.module("tui"));

Community โ€‹

License โ€‹

MIT License - see LICENSE

Released under the MIT License.