ziglibs / ansi-term

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

API ideas #9

Open data-man opened 4 years ago

data-man commented 4 years ago

As result:

   debug.print("{fg} FG red {bg} BG green {} default", { .Red, .Green, .Reset });
joachimschmidt557 commented 4 years ago

Counter-proposal which works with #10 as well:

std.debug.print("this is normal text {this is also normal} {this is red}", .{ Style.default, Style{.foreground = Color.red} });
joachimschmidt557 commented 4 years ago

This is of course convenient for enabling applications to have colored terminal output. But I think this library should also be robust and still provide the low-level interfaces like updateStyle in order to minimize the bytes written to the terminal.

joachimschmidt557 commented 4 years ago

Another counter-proposal: I think the most common use case for this high-level printing would be in association with compile-time known styles. This means we can design a function

pub fn red(comptime text: []const u8) []const u8

and use this for example:

std.debug.print("{}: " ++ Styled.red("Path {} does not exist"), .{ time(), path });