@@ -31,7 +31,7 @@ This project aims to enhance terminal applications by enabling developers to use
3131
3232Chroma requires Zig version 0.12.0-dev.2701+d18f52197 or newer. You can include it in your Zig project by adding it as a package in your ` build.zig ` file:
3333
34- 1 . Fetch the project using ` zig fetch `
34+ 1 . Fetch the project using ` zig fetch ` (recommended !)
3535
3636``` bash
3737zig fetch --save https://github.com/adia-dev/chroma-zig/archive/refs/tags/v0.1.0.tar.gz
@@ -43,59 +43,22 @@ Or manually paste this in your `build.zig.zon`
4343.dependencies = .{
4444 // other deps...
4545 .chroma = .{
46- .url = "https://github.com/adia-dev/chroma-zig/archive/refs/tags/v0.1.0 .tar.gz",
47- .hash = "12203dca2231f1d4e1fe9e0c2f28e6497db76c24434b6ca9b872eaca9d40f45d97ba ",
46+ .url = "https://github.com/adia-dev/chroma-zig/archive/refs/tags/v0.1.1 .tar.gz",
47+ .hash = "<HASH_OF_THE_RELEASE> ",
4848 },
4949 // ...
5050},
5151```
5252
53- 2 . In your ` build.zig ` , add Chroma as a package:
53+ Note that if you do not know the hash of the release, zig will spit it out as an error in the console.
5454
55- ``` zig
56- const std = @import("std");
57-
58- pub fn build(b: *std.Build) void {
59- const target = b.standardTargetOptions(.{});
60- const optimize = b.standardOptimizeOption(.{});
61-
62- // Add the chroma dep
63- const chroma = b.dependency("chroma", .{});
64-
65- const exe = b.addExecutable(.{
66- .name = "use-chroma",
67- .root_source_file = .{ .path = "src/main.zig" },
68- .target = target,
69- .optimize = optimize,
70- });
71-
72- // Adding the module to the executable
73- exe.root_module.addImport("chroma", chroma.module("chroma"));
74-
75- b.installArtifact(exe);
76-
77- const run_cmd = b.addRunArtifact(exe);
78- run_cmd.step.dependOn(b.getInstallStep());
79-
80- if (b.args) |args| {
81- run_cmd.addArgs(args);
82- }
83-
84- const run_step = b.step("run", "Run the app");
85- run_step.dependOn(&run_cmd.step);
86-
87- const exe_unit_tests = b.addTest(.{
88- .root_source_file = .{ .path = "src/main.zig" },
89- .target = target,
90- .optimize = optimize,
91- });
92-
93- const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
94-
95- const test_step = b.step("test", "Run unit tests");
96- test_step.dependOn(&run_exe_unit_tests.step);
97- }
55+ 2 . In your ` build.zig ` , add Chroma as a module:
9856
57+ ``` zig
58+ // Add the chroma dep
59+ const chroma = b.dependency("chroma", .{});
60+ // Adding the module to the executable
61+ exe.root_module.addImport("chroma", chroma.module("chroma"));
9962```
10063
101643 . Use ` zig build ` to compile your project.
@@ -109,34 +72,44 @@ const std = @import("std");
10972const chroma = @import("lib.zig");
11073
11174pub fn main() !void {
112- const examples = [_]struct { fmt: []const u8, arg: []const u8 }{
113- // Ansi fg and bg
114- .{ .fmt = "{yellow}ANSI {s}", .arg = "SUPPORTED" },
115- .{ .fmt = "{blue}JJK is the best new {s}", .arg = "gen" },
116- .{ .fmt = "{red}Disagree and {cyan}Satoru Gojo will throw a {magenta}{s}{reset} on you", .arg = "purple" },
117- .{ .fmt = "{bgMagenta}{white}Yuji Itadori's resolve: {s}", .arg = "I'll eat the finger." },
118- .{ .fmt = "{bgYellow}{black}With this treasure I summon: {s}", .arg = "Mahoraga or Makora idk" },
119- .{ .fmt = "{bgBlue}{white}LeBron James: {s}", .arg = "Strive for greatness." },
120- .{ .fmt = "{red}Michael Jordan's legacy: {s}", .arg = "The GOAT" },
121- .{ .fmt = "{green}Please Lonzo Ball comeback in {s}", .arg = "2024" },
122- .{ .fmt = "{blue}JJK is the best new {s}", .arg = "gen" },
123-
124- // Ansi 256 extended
125- .{ .fmt = "\n{221}256 Extended set too ! {s}", .arg = "eheh" },
126- .{ .fmt = "{121}I don't have anything to say finding examples is hard {s}", .arg = "shirororororo" },
127-
128- // TrueColors
129- .{ .fmt = "\n{221;10;140}How about {13;45;200}{s} ??", .arg = "true colors" },
130- .{ .fmt = "{255;202;255}Toge Inumaki says: {s}", .arg = "Salmon" },
131- .{ .fmt = "{255;105;180}Nobara Kugisaki's fierce {s}", .arg = "Nail Hammer" },
132- .{ .fmt = "{10;94;13}Juujika no {s}", .arg = "Rokunin" },
75+ const examples = [_]struct { fmt: []const u8, arg: ?[]const u8 }{
76+ // Basic color and style
77+ .{ .fmt = "{bold,red}Bold and Red{reset}", .arg = null },
78+ // Combining background and foreground with styles
79+ .{ .fmt = "{fg:cyan,bg:magenta}{underline}Cyan on Magenta underline{reset}", .arg = null },
80+ // Nested styles and colors
81+ .{ .fmt = "{green}Green {bold}and Bold{reset,blue,italic} to blue italic{reset}", .arg = null },
82+ // Extended ANSI color with arg example
83+ .{ .fmt = "{bg:120}Extended ANSI {s}{reset}", .arg = "Background" },
84+ // True color specification
85+ .{ .fmt = "{fg:255;100;0}True Color Orange Text{reset}", .arg = null },
86+ // Mixed color and style formats
87+ .{ .fmt = "{bg:28,italic}{fg:231}Mixed Background and Italic{reset}", .arg = null },
88+ // Unsupported/Invalid color code >= 256, Error thrown at compile time
89+ // .{ .fmt = "{fg:999}This should not crash{reset}", .arg = null },
90+ // Demonstrating blink, note: may not be supported in all terminals
91+ .{ .fmt = "{blink}Blinking Text (if supported){reset}", .arg = null },
92+ // Using dim and reverse video
93+ .{ .fmt = "{dim,reverse}Dim and Reversed{reset}", .arg = null },
94+ // Custom message with dynamic content
95+ .{ .fmt = "{blue,bg:magenta}User {bold}{s}{reset,0;255;0} logged in successfully.", .arg = "Charlie" },
96+ // Combining multiple styles and reset
97+ .{ .fmt = "{underline,cyan}Underlined Cyan{reset} then normal", .arg = null },
98+ // Multiple format specifiers for complex formatting
99+ .{ .fmt = "{fg:144,bg:52,bold,italic}Fancy {underline}Styling{reset}", .arg = null },
100+ // Jujutsu Kaisen !!
101+ .{ .fmt = "{bg:72,bold,italic}Jujutsu Kaisen !!{reset}", .arg = null },
133102 };
134103
135104 inline for (examples) |example| {
136- std.debug.print(chroma.format(example.fmt) ++ "\n", .{example.arg});
105+ if (example.arg) |arg| {
106+ std.debug.print(chroma.format(example.fmt) ++ "\n", .{arg});
107+ } else {
108+ std.debug.print(chroma.format(example.fmt) ++ "\n", .{});
109+ }
137110 }
138111
139- std.debug.print(chroma.format("{blue}Eventually, the {red}formatting{reset} looks like {130;43;122}{s} !\n"), .{"this"});
112+ std.debug.print(chroma.format("{blue}{underline} Eventually{reset} , the {red}formatting{reset} looks like {130;43;122}{s}!\n"), .{"this"});
140113}
141114
142115```
0 commit comments