@@ -51,14 +51,52 @@ Chroma is a Zig library for advanced ANSI color and text styling in terminal out
51512 . ** Import and Use:**
5252 After building and installing, you can import ` chroma ` into your Zig code:
5353
54- ``` zig
55- const std = @import("std");
56- const chroma = @import("lib.zig");
54+ ``` zig
55+ const std = @import("std");
56+ const chroma = @import("lib.zig");
57+
58+ pub fn main() !void {
59+ const examples = [_]struct { fmt: []const u8, arg: ?[]const u8 }{
60+ // Basic color and style
61+ .{ .fmt = "{bold,red}Bold and Red{reset}", .arg = null },
62+ // Combining background and foreground with styles
63+ .{ .fmt = "{fg:cyan,bg:magenta}{underline}Cyan on Magenta underline{reset}", .arg = null },
64+ // Nested styles and colors
65+ .{ .fmt = "{green}Green {bold}and Bold{reset,blue,italic} to blue italic{reset}", .arg = null },
66+ // Extended ANSI color with arg example
67+ .{ .fmt = "{bg:120}Extended ANSI {s}{reset}", .arg = "Background" },
68+ // True color specification
69+ .{ .fmt = "{fg:255;100;0}True Color Orange Text{reset}", .arg = null },
70+ // Mixed color and style formats
71+ .{ .fmt = "{bg:28,italic}{fg:231}Mixed Background and Italic{reset}", .arg = null },
72+ // Unsupported/Invalid color code >= 256, Error thrown at compile time
73+ // .{ .fmt = "{fg:999}This should not crash{reset}", .arg = null },
74+ // Demonstrating blink, note: may not be supported in all terminals
75+ .{ .fmt = "{blink}Blinking Text (if supported){reset}", .arg = null },
76+ // Using dim and reverse video
77+ .{ .fmt = "{dim,reverse}Dim and Reversed{reset}", .arg = null },
78+ // Custom message with dynamic content
79+ .{ .fmt = "{blue,bg:magenta}User {bold}{s}{reset,0;255;0} logged in successfully.", .arg = "Charlie" },
80+ // Combining multiple styles and reset
81+ .{ .fmt = "{underline,cyan}Underlined Cyan{reset} then normal", .arg = null },
82+ // Multiple format specifiers for complex formatting
83+ .{ .fmt = "{fg:144,bg:52,bold,italic}Fancy {underline}Styling{reset}", .arg = null },
84+ // Jujutsu Kaisen !!
85+ .{ .fmt = "{bg:72,bold,italic}Jujutsu Kaisen !!{reset}", .arg = null },
86+ };
87+
88+ inline for (examples) |example| {
89+ if (example.arg) |arg| {
90+ std.debug.print(chroma.format(example.fmt) ++ "\n", .{arg});
91+ } else {
92+ std.debug.print(chroma.format(example.fmt) ++ "\n", .{});
93+ }
94+ }
95+
96+ std.debug.print(chroma.format("{blue}{underline}Eventually{reset}, the {red}formatting{reset} looks like {130;43;122}{s}!\n"), .{"this"});
97+ }
5798
58- pub fn main() !void {
59- std.debug.print(chroma.format("{bold,red}Hello, Red World!{reset}\n"), .{});
60- }
61- ```
99+ ```
62100
631013 . ** Run and Test:**
64102 - Build your project with ` zig build ` .
0 commit comments