const std = @import("std"); pub const AppError = error{ MissingName, EmptyInput, }; pub const Theme = enum { light, dark, solarized, }; pub const Settings = struct { name: []const u8, retries: u8 = 3, theme: Theme = .dark, tags: []const []const u8 = &.{}, pub fn validate(self: Settings) AppError!void { if (self.name.len == 0) return error.MissingName; if (self.tags.len == 0) return error.EmptyInput; } }; pub fn summarize(settings: Settings) []const u8 { return switch (settings.theme) { .light => "bright", .dark => "focused", .solarized => "balanced", }; } pub fn findLongestTag(tags: []const []const u8) ?[]const u8 { var longest: ?[]const u8 = null; for (tags) |tag| { if (longest == null or tag.len > longest.?.len) { longest = tag; } } return longest; } pub fn renderExample(writer: anytype) !void { const settings = Settings{ .name = "Nova Zig", .tags = &.{ "tree-sitter", "zls", "tasks" }, }; try settings.validate(); try writer.print("theme summary: {s}\n", .{summarize(settings)}); if (findLongestTag(settings.tags)) |tag| { try writer.print("longest tag: {s}\n", .{tag}); } const block_value = label: { var total: usize = 0; for (settings.tags) |tag| total += tag.len; break :label total; }; try writer.print("combined tag length: {}\n", .{block_value}); const multiline = \\sample text block \\with enough lines to make folding obvious \\inside Nova's editor ; _ = multiline; } test "showcase remains valid" { var output: std.ArrayList(u8) = .empty; defer output.deinit(std.testing.allocator); try renderExample(output.writer(std.testing.allocator)); try std.testing.expect(std.mem.indexOf(u8, output.items, "theme summary") != null); }