Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100const std = @import("std");
const W = std.Io.Writer;const E = W.Error;
pub const Style = enum(u8) { reset, bold, dim, italic, underline, blink, inverse, invisible, strikethrough,
pub fn ansi(self: Style) u8 { return @intFromEnum(self); }};
pub fn style(w: *W, b: Style) E!void { try base(w, b.ansi());}
pub const Color = enum(u8) { black, red, green, yellow, blue, magenta, cyan, white, default,
pub fn int(n: u8) Color { return @enumFromInt(n); } pub fn foreground(self: Color) u8 { return @intFromEnum(self) + 30; } pub fn background(self: Color) u8 { return @intFromEnum(self) + 40; } pub fn foreground_bright(self: Color) u8 { return @intFromEnum(self) + 90; } pub fn background_bright(self: Color) u8 { return @intFromEnum(self) + 100; }};
pub fn fg(w: *W, color: Color) E!void { try base(w, color.foreground());}pub fn bg(w: *W, color: Color) E!void { try base(w, color.background());}pub fn fg_bright(w: *W, color: Color) E!void { try base(w, color.foreground_bright());}pub fn bg_bright(w: *W, color: Color) E!void { try base(w, color.background_bright());}
pub fn fg_256(w: *W, color: u8) E!void { try params(w, &[_]u8{ 38, 5, color });}pub fn bg_256(w: *W, color: u8) E!void { try params(w, &[_]u8{ 48, 5, color });}
pub fn fg_rgb(w: *W, red: u8, green: u8, blue: u8) E!void { try params(w, &[_]u8{ 38, 2, red, green, blue });}pub fn bg_rgb(w: *W, red: u8, green: u8, blue: u8) E!void { try params(w, &[_]u8{ 48, 2, red, green, blue });}
fn params(w: *W, p: []const u8) E!void { try csi(w); for (p, 0..) |c, i| { try w.printInt(c, 10, .lower, .{}); if (i < p.len - 1) try w.writeByte(';'); } try w.writeByte('m');}
fn base(w: *W, c: u8) E!void { try csi(w); try w.printInt(c, 10, .lower, .{}); try w.writeByte('m');}
fn csi(w: *W) E!void { try w.writeByte('\x1B'); try w.writeByte('[');}