Skip to content

chardoncs/zig-ansi-parse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zig-ansi-parse

Comptime-proof ANSI format parsing library for Zig.

How it works?

Install

  1. Fetch it in your project, <version> is the version you want
zig fetch --save https://github.com/chardoncs/zig-ansi-parse/archive/refs/tags/v<version>.tar.gz

Or fetch the git repo for latest updates

zig fetch --save git+https://github.com/chardoncs/zig-ansi-parse
  1. Configure your build.zig.
const ansi_parse = b.dependency("ansi-parse", .{});
exe.root_module.addImport("ansi-parse", ansi_parse.module("ansi-parse"));

At a glance

const std = @import("std");
const parseComptime = @import("ansi-parse").parseComptime;

const demo_text = parseComptime(
    \\<CYAN>Greetings!</> I'm <B>bold</> and <BLUE;B>blue</>
    \\<NYAN>Ignore this</>
    \\\<escaped>
    \\<!TAB>tabbed<!LF>Ollal<!CR>Hello
    \\<!TAB*3>Three tabs
    \\
, .{} // Options
);

pub fn main() !void {
    std.debug.print(demo_text, .{});
}

Options

Name Default value Description
branch_quota 200,000 (Comptime only) Evaluation branch quota. A larger quota can prevent the compiler from giving up caused by loops
out_size input.len * 4 (Comptime only) Capacity of the output string, set a larger value if the output is truncated