ziglibs / ansi-term

Zig library for dealing with ANSI terminals
MIT License
66 stars 7 forks source link

custom `format` function #31

Open illfygli opened 8 months ago

illfygli commented 8 months ago

Do you think it would make sense to include a format function, so that Styles can be printed directly?

I added this,

pub fn format(value: Self, comptime _: []const u8, _: std.fmt.FormatOptions, writer: anytype) std.os.WriteError!void {
    try @import("format.zig").updateStyle(writer, value, null);
}

while porting a program away from a different lib, where I had added something similar, and it made the port easy, if suboptimal.

And another thing, when you don't want the cursor to be misplaced, you need yet more escape codes around the bytes that aren't displayed. Currently I have a wrapping writer that adds them as neccessary, but maybe that should be part of the lib in some way?

Would be happy to send patches for those things.