This repository has no description
3

Configure Feed

Select the types of activity you want to include in your feed.

ansi: full terminal style & color

mwahh <3

june (Jul 15, 2026, 5:36 PM +0200) e3262837 3353e243

+96
+96
src/ansi.zig
··· 1 + const std = @import("std"); 2 + 3 + const W = std.Io.Writer; 4 + const E = W.Error; 5 + 6 + pub const Style = enum(u8) { 7 + reset, 8 + bold, 9 + dim, 10 + italic, 11 + underline, 12 + blink, 13 + inverse, 14 + invisible, 15 + strikethrough, 16 + 17 + pub fn ansi(self: Style) u8 { 18 + return @intFromEnum(self); 19 + } 20 + }; 21 + 22 + pub fn style(w: *W, b: Style) E!void { 23 + try base(w, b.ansi()); 24 + } 25 + 26 + pub const Color = enum(u8) { 27 + black, 28 + red, 29 + green, 30 + yellow, 31 + blue, 32 + magenta, 33 + cyan, 34 + white, 35 + default, 36 + 37 + pub fn foreground(self: Color) u8 { 38 + return @intFromEnum(self) + 30; 39 + } 40 + pub fn background(self: Color) u8 { 41 + return @intFromEnum(self) + 40; 42 + } 43 + pub fn foreground_bright(self: Color) u8 { 44 + return @intFromEnum(self) + 90; 45 + } 46 + pub fn background_bright(self: Color) u8 { 47 + return @intFromEnum(self) + 100; 48 + } 49 + }; 50 + 51 + pub fn fg(w: *W, color: Color) E!void { 52 + try base(w, color.foreground()); 53 + } 54 + pub fn bg(w: *W, color: Color) E!void { 55 + try base(w, color.background()); 56 + } 57 + pub fn fg_bright(w: *W, color: Color) E!void { 58 + try base(w, color.foreground_bright()); 59 + } 60 + pub fn bg_bright(w: *W, color: Color) E!void { 61 + try base(w, color.background_bright()); 62 + } 63 + 64 + pub fn fg_256(w: *W, color: u8) E!void { 65 + try params(w, &[_]u8{ 38, 5, color }); 66 + } 67 + pub fn bg_256(w: *W, color: u8) E!void { 68 + try params(w, &[_]u8{ 48, 5, color }); 69 + } 70 + 71 + pub fn fg_rgb(w: *W, red: u8, green: u8, blue: u8) E!void { 72 + try params(w, &[_]u8{ 38, 2, red, green, blue }); 73 + } 74 + pub fn bg_rgb(w: *W, red: u8, green: u8, blue: u8) E!void { 75 + try params(w, &[_]u8{ 48, 2, red, green, blue }); 76 + } 77 + 78 + fn params(w: *W, p: []const u8) E!void { 79 + try csi(w); 80 + for (p, 0..) |c, i| { 81 + try w.printInt(c, 10, .lower, .{}); 82 + if (i < p.len - 1) try w.writeByte(';'); 83 + } 84 + try w.writeByte('m'); 85 + } 86 + 87 + fn base(w: *W, c: u8) E!void { 88 + try csi(w); 89 + try w.printInt(c, 10, .lower, .{}); 90 + try w.writeByte('m'); 91 + } 92 + 93 + fn csi(w: *W) E!void { 94 + try w.writeByte('\x1B'); 95 + try w.writeByte('['); 96 + }