ansi-term icon indicating copy to clipboard operation
ansi-term copied to clipboard

API ideas

Open data-man opened this issue 5 years ago • 3 comments

  • implement format fn for Color and FontStyle types
  • with custom specifiers: if specifier is empty then write CSI-sequence bg & fg specifiers for Color type: treat value as background & foreground respectively np: don't write CSI prefix for intelligent updates

As result:

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

data-man avatar Aug 23 '20 04:08 data-man

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 avatar Sep 04 '20 17:09 joachimschmidt557

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 avatar Sep 04 '20 17:09 joachimschmidt557

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 });

joachimschmidt557 avatar Sep 04 '20 18:09 joachimschmidt557