All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 48s
39 lines
1.1 KiB
Zig
39 lines
1.1 KiB
Zig
const std = @import("std");
|
|
|
|
pub const Color = enum(u8) {
|
|
default = 0,
|
|
black = 16,
|
|
light_red = 1,
|
|
light_green,
|
|
light_yellow,
|
|
light_blue,
|
|
light_magenta,
|
|
light_cyan,
|
|
light_grey,
|
|
grey,
|
|
red,
|
|
green,
|
|
yellow,
|
|
blue,
|
|
magenta,
|
|
cyan,
|
|
white,
|
|
// TODO add further colors as described in https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b # Color / Graphics Mode - 256 Colors
|
|
|
|
pub inline fn write(this: Color, writer: anytype, comptime coloring: enum { fg, bg, ul }) !void {
|
|
if (this == .default) {
|
|
switch (coloring) {
|
|
.fg => try std.fmt.format(writer, "39", .{}),
|
|
.bg => try std.fmt.format(writer, "49", .{}),
|
|
.ul => try std.fmt.format(writer, "59", .{}),
|
|
}
|
|
} else {
|
|
switch (coloring) {
|
|
.fg => try std.fmt.format(writer, "38;5;{d}", .{@intFromEnum(this)}),
|
|
.bg => try std.fmt.format(writer, "48;5;{d}", .{@intFromEnum(this)}),
|
|
.ul => try std.fmt.format(writer, "58;5;{d}", .{@intFromEnum(this)}),
|
|
}
|
|
}
|
|
}
|
|
};
|