Skip to content

Styles

tint.zig provides composable text styles.

Style Composition

Create styles with the style function:

zig
const error_style = tint.style(.{
    .fg = tint.hex(0xEF4444),
    .bold = true,
});

std.debug.print("{s}Error message{s}\n", .{
    error_style.toAnsi(),
    tint.reset,
});

Style Options

OptionTypeDescription
fg?ColorForeground color
bg?ColorBackground color
underline_color?ColorUnderline color
boldboolBold text (SGR 1)
dimboolDim text (SGR 2)
italicboolItalic text (SGR 3)
underlineboolUnderlined text (SGR 4)
blinkboolBlinking text (SGR 5)
rapid_blinkboolRapid blink (SGR 6)
reverseboolReversed text (SGR 7)
hiddenboolHidden text (SGR 8)
strikethroughboolStrikethrough text (SGR 9)
super_scriptboolSuperscript (SGR 73)
sub_scriptboolSubscript (SGR 74)
frakturboolFraktur/Gothic (SGR 20)
overlineboolOverlined text (SGR 53)
frameboolFramed text (SGR 51)
encircleboolEncircled text (SGR 52)

Extending Styles

Use .with() to create extended styles:

zig
const base = tint.style(.{
    .fg = .{ .ansi4 = .green },
    .bold = true,
});

const warning = base.with(.{
    .underline = true,
});

Convenience Methods

zig
const s = tint.style(.{ .bold = true });
const with_fg = s.withFg(.{ .ansi4 = .red });      // Set foreground
const with_bg = s.withBg(.{ .ansi4 = .blue });      // Set background
const with_ul = s.withUnderline(.{ .ansi4 = .green }); // Set underline color

Style Composition

Merge two styles with compose():

zig
const s1 = tint.style(.{ .bold = true, .fg = .{ .ansi4 = .red } });
const s2 = tint.style(.{ .italic = true, .bg = .{ .ansi4 = .blue } });
const composed = tint.Style.compose(s1, s2);
// Result: bold=true, italic=true, fg=red, bg=blue

Preset Styles

zig
const err = tint.presets.err_style(.{ .ansi4 = .red });    // Bold red
const warn = tint.presets.warning(.{ .ansi4 = .yellow });  // Bold yellow
const ok = tint.presets.success(.{ .ansi4 = .green });     // Bold green
const info = tint.presets.info(.{ .ansi4 = .cyan });       // Normal cyan
const debug = tint.presets.debug(.{ .ansi4 = .bright_black }); // Dim gray
const link = tint.presets.link(.{ .ansi4 = .blue });       // Underlined blue
const code = tint.presets.code(.{ .ansi4 = .white }, .{ .ansi4 = .black }); // White on black
const hdr = tint.presets.header(.{ .ansi4 = .bright_white }); // Bold underlined
const muted = tint.presets.muted(.{ .ansi4 = .bright_black }); // Dim
const hl = tint.presets.highlight(.{ .ansi4 = .black }, .{ .ansi4 = .yellow }); // Bold black on yellow

Individual Resets

zig
tint.reset_bold           // SGR 22
tint.reset_italic         // SGR 23
tint.reset_underline      // SGR 24
tint.reset_blink          // SGR 25
tint.reset_reverse        // SGR 27
tint.reset_hidden         // SGR 28
tint.reset_strikethrough  // SGR 29
tint.reset_overline       // SGR 55
tint.reset_fg             // SGR 39
tint.reset_bg             // SGR 49
tint.reset_underline_color // SGR 59

Full Reset

zig
tint.reset  // SGR 0 - clears all attributes

Released under the MIT License.