//! Hello World example for zcatui. //! //! Demonstrates basic usage of the library: //! - Creating a Terminal //! - Rendering a Block with a title //! - Using Layout to split the screen //! - Displaying a Paragraph const std = @import("std"); const zcatui = @import("zcatui"); const Terminal = zcatui.Terminal; const Buffer = zcatui.Buffer; const Rect = zcatui.Rect; const Layout = zcatui.Layout; const Constraint = zcatui.Constraint; const Style = zcatui.Style; const Color = zcatui.Color; const block_mod = @import("zcatui").widgets.block_mod; const Block = block_mod.Block; const Borders = block_mod.Borders; const Paragraph = zcatui.widgets.Paragraph; pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); // Initialize terminal var term = try Terminal.init(allocator); defer term.deinit(); // Draw the UI try term.draw(render); // Wait for 'q' to quit const stdin = std.fs.File.stdin(); var buf: [1]u8 = undefined; while (true) { const bytes_read = stdin.read(&buf) catch break; if (bytes_read == 0) break; if (buf[0] == 'q') break; // Redraw on any key try term.draw(render); } } fn render(area: Rect, buf: *Buffer) void { // Split screen: header (3 rows) + content (rest) const chunks = Layout.vertical(&.{ Constraint.length(3), Constraint.min(0), }).split(area); // Header block const header = Block.init() .title(" zcatui Demo ") .setBorders(Borders.all) .borderStyle(Style.default.fg(Color.cyan)); header.render(chunks.get(0), buf); // Content area with paragraph const content_block = Block.init() .title(" Welcome ") .setBorders(Borders.all) .borderStyle(Style.default.fg(Color.green)); const content_area = chunks.get(1); content_block.render(content_area, buf); // Paragraph inside the content block const text = \\Hello from zcatui! \\ \\This is a TUI library for Zig, inspired by ratatui. \\ \\Features: \\ - Immediate mode rendering \\ - Layout system with constraints \\ - Styled text and colors \\ - Reusable widgets \\ \\Press 'q' to quit. ; const para = Paragraph.init(text) .style(Style.default.fg(Color.white)) .setWrap(.word); para.render(content_block.inner(content_area), buf); }