{"id":18866007,"url":"https://github.com/adia-dev/chroma-zig","last_synced_at":"2025-09-16T13:13:44.256Z","repository":{"id":222397268,"uuid":"757131681","full_name":"adia-dev/chroma-zig","owner":"adia-dev","description":null,"archived":false,"fork":false,"pushed_at":"2024-12-25T14:08:24.000Z","size":348,"stargazers_count":16,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T10:58:10.755Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adia-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-13T21:36:07.000Z","updated_at":"2024-12-29T11:57:21.000Z","dependencies_parsed_at":"2024-08-15T21:15:22.358Z","dependency_job_id":"3b6c488b-c63f-42d7-a730-ba75cd14c11b","html_url":"https://github.com/adia-dev/chroma-zig","commit_stats":null,"previous_names":["adia-dev/chroma-zig"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fchroma-zig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fchroma-zig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fchroma-zig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adia-dev%2Fchroma-zig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adia-dev","download_url":"https://codeload.github.com/adia-dev/chroma-zig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231918540,"owners_count":18445748,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T05:05:17.253Z","updated_at":"2025-09-16T13:13:44.129Z","avatar_url":"https://github.com/adia-dev.png","language":"Zig","readme":"# Chroma\n\n**Version:** 0.13.0  \n**License:** MIT  \n**Language:** [Zig](https://ziglang.org)\n\nChroma is a Zig library for advanced ANSI color and text styling in terminal output. It allows developers to dynamically format strings with embedded placeholders (e.g. `{red}`, `{bold}`, `{fg:255;100;0}` for true color) and converts them into ANSI escape sequences. This makes it easy to apply complex styles, switch between foreground/background colors, and reset formatting on the fly—all at compile time.\n\n\u003cimg width=\"720\" alt=\"chroma\" src=\"https://github.com/user-attachments/assets/251f16b7-8cfc-4222-86b6-699d05976c4b\"\u003e\n\n## ✨ Features\n\n- **Simple, Readable Syntax:**  \n  Use `{red}`, `{bold}`, or `{green,bgBlue}` inline within strings for clear and maintainable code.\n\n- **Comprehensive ANSI Codes:**  \n  Support for standard colors, background colors, bold, italic, underline, dim, and even less commonly supported effects like `blink` and `reverse`.\n\n- **Extended and True Color Support:**  \n  Take advantage of ANSI 256 extended color codes and true color (24-bit) formats using syntax like `{fg:120}`, `{bg:28}`, or `{fg:255;100;0}` for fine-grained color control.\n\n- **Compile-Time Safety:**  \n  Chroma verifies format strings at compile time, reducing runtime errors and ensuring your formatting instructions are valid.\n\n- **Reset-Friendly:**  \n  Automatically appends `\"\\x1b[0m\"` when necessary, ensuring that styles don’t “bleed” into subsequent output.\n\n## 🚀 Getting Started\n\n### Prerequisite\n\n1. Fetch the project using `zig fetch`\n\n```bash\nzig fetch --save https://github.com/adia-dev/chroma-zig/archive/refs/heads/main.zip\n```\n\nOr manually paste this in your `build.zig.zon`\n\n```zig\n.dependencies = .{\n    // other deps...\n    .chroma = .{\n        .url = \"https://github.com/adia-dev/chroma-zig/archive/refs/heads/main.zip\",\n        .hash = \"12209a8a991121bba3b21f31d275588690dc7c0d7fa9c361fd892e782dd88e0fb2ba\",\n    },\n    // ...\n},\n```\n\n1. **Add Chroma to Your Zig Project:**\n   Include Chroma as a dependency in your `build.zig` or your `build.zig.zon`. For example:\n\n   ```zig\n   const std = @import(\"std\");\n\n   pub fn build(b: *std.Build) void {\n       const target = b.standardTargetOptions(.{});\n       const optimize = b.standardOptimizeOption(.{});\n\n       const lib = b.addStaticLibrary(.{\n           .name = \"chroma\",\n           .root_source_file = .{ .src_path = .{ .owner = b, .sub_path = \"src/lib.zig\" } },\n           .target = target,\n           .optimize = optimize,\n       });\n\n       b.installArtifact(lib);\n   }\n   ```\n\n2. **Import and Use:**\n   After building and installing, you can import `chroma` into your Zig code:\n\n```zig\nconst std = @import(\"std\");\nconst chroma = @import(\"lib.zig\");\n\npub fn main() !void {\n    const examples = [_]struct { fmt: []const u8, arg: ?[]const u8 }{\n        // Basic color and style\n        .{ .fmt = \"{bold,red}Bold and Red{reset}\", .arg = null },\n        // Combining background and foreground with styles\n        .{ .fmt = \"{fg:cyan,bg:magenta}{underline}Cyan on Magenta underline{reset}\", .arg = null },\n        // Nested styles and colors\n        .{ .fmt = \"{green}Green {bold}and Bold{reset,blue,italic} to blue italic{reset}\", .arg = null },\n        // Extended ANSI color with arg example\n        .{ .fmt = \"{bg:120}Extended ANSI {s}{reset}\", .arg = \"Background\" },\n        // True color specification\n        .{ .fmt = \"{fg:255;100;0}True Color Orange Text{reset}\", .arg = null },\n        // Mixed color and style formats\n        .{ .fmt = \"{bg:28,italic}{fg:231}Mixed Background and Italic{reset}\", .arg = null },\n        // Unsupported/Invalid color code \u003e= 256, Error thrown at compile time\n        // .{ .fmt = \"{fg:999}This should not crash{reset}\", .arg = null },\n        // Demonstrating blink, note: may not be supported in all terminals\n        .{ .fmt = \"{blink}Blinking Text (if supported){reset}\", .arg = null },\n        // Using dim and reverse video\n        .{ .fmt = \"{dim,reverse}Dim and Reversed{reset}\", .arg = null },\n        // Custom message with dynamic content\n        .{ .fmt = \"{blue,bg:magenta}User {bold}{s}{reset,0;255;0} logged in successfully.\", .arg = \"Charlie\" },\n        // Combining multiple styles and reset\n        .{ .fmt = \"{underline,cyan}Underlined Cyan{reset} then normal\", .arg = null },\n        // Multiple format specifiers for complex formatting\n        .{ .fmt = \"{fg:144,bg:52,bold,italic}Fancy {underline}Styling{reset}\", .arg = null },\n        // Jujutsu Kaisen !!\n        .{ .fmt = \"{bg:72,bold,italic}Jujutsu Kaisen !!{reset}\", .arg = null },\n    };\n\n    inline for (examples) |example| {\n        if (example.arg) |arg| {\n            std.debug.print(chroma.format(example.fmt) ++ \"\\n\", .{arg});\n        } else {\n            std.debug.print(chroma.format(example.fmt) ++ \"\\n\", .{});\n        }\n    }\n\n    std.debug.print(chroma.format(\"{blue}{underline}Eventually{reset}, the {red}formatting{reset} looks like {130;43;122}{s}!\\n\"), .{\"this\"});\n}\n\n```\n\n3. **Run and Test:**\n   - Build your project with `zig build`.\n   - Run your binary and see the styled output in your terminal!\n\n## 🧪 Testing\n\nChroma includes a suite of unit tests to ensure reliability:\n\n```bash\nzig build test\n```\n\nIf all tests pass, you’re good to go!\n\n## 🔧 Configuration\n\nChroma works out-of-the-box. For more complex scenarios (e.g., custom labels, multiple color formats), refer to `src/lib.zig` and `src/ansi.zig` for detailed code comments that explain available options and their intended usage.\n\n## 📦 New in Version 0.13.0\n\n- **Updated Compatibility:** Now aligned with Zig `0.13.0`.\n- **Improved Parser Logic:** More robust handling of multiple formats within the same placeholder.\n- **Better Testing:** Additional tests ensure extended color and true color formats behave as expected.\n- **Performance Tweaks:** Minor compile-time optimizations for faster builds.\n\n## 🤝 Contributing\n\nContributions are welcome! To get involved:\n\n1. **Fork \u0026 Clone:**  \n   Fork the repository and clone it locally.\n\n2. **Branch \u0026 Develop:**  \n   Create a new branch and implement your changes or new features.\n\n3. **Test \u0026 Document:**  \n   Run `zig build test` to ensure your changes haven’t broken anything. Update or add documentation as needed.\n\n4. **Pull Request:**  \n   Submit a Pull Request describing what you changed and why. We’ll review and merge it if everything looks good.\n\n## 📝 License\n\n[MIT License](./LICENSE)\n\n_Chroma aims to simplify ANSI coloring in Zig, making your command-line tools, logs, and output more expressive and visually appealing._\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadia-dev%2Fchroma-zig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadia-dev%2Fchroma-zig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadia-dev%2Fchroma-zig/lists"}