zhuyadong/xterm256.zig
print text with xterm256 style
xterm256
Colors and StylesIn the project root directory:
zig fetch "git+https://github.com/zhuyadong/xterm256.zig" --save=xterm256
If you want to install a specific version:
zig fetch "git+https://github.com/zhuyadong/xterm256.zig#<ref id>" --save=xterm256
const xterm = @import("xterm256");
// Print "Hello" in red
xterm.print(.{.fg = .red}, "Hello", .{});
// Print "Hello" in red with a white background
xterm.print(.{.fg = .{.r=5}, .bg = .white}, "Hello", .{});
// Print "Hello" with color number 222
xterm.print(.{.fg = .x222}, "Hello", .{});
// Print "Hello" in bold red
xterm.print(.{.fg = .red, .style = .{.bold}}, "Hello", .{});
// If there is a `prefix`, only the `prefix` part will be colored
xterm.print(.{.fg = .red, .prefix="error:"}, " something wrong.", .{});
// Save the sequence to print "Hello" in red to buf
var buf: [128]u8 = undefined;
_ = try xterm.bufPrint(&buf, .{.fg = .red}, "Hello", .{});
// Complex style
const complexStyle = .{
.fg = .x222,
.bg = .{.b = 5, .g = 5},
.style = .{.bold, .underline},
.prefix = "complex:",
};
xterm.print(complexStyle, "Hello", .{});
.{
.fg = <color>,
.bg = <color>,
.style = .{.style1, .style2 ...},
.prefix="prefix text"
}
Where <color>
can be one of the following formats:
In the
rgb
format, you can omit 1-2 ofr
,g
,b
<color_name>
includes the following items:
style
includes the following items: