add(examples/styles): text and color styling possiblities
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 39s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 39s
This also contains some minor refactoring to improve the readability and understandability of the library (i.e. renaming of Style.Attributes to Style.Emphasis).
This commit is contained in:
@@ -22,7 +22,7 @@ pub const Underline = enum {
|
||||
dashed,
|
||||
};
|
||||
|
||||
pub const Attribute = enum(u8) {
|
||||
pub const Emphasis = enum(u8) {
|
||||
reset = 0,
|
||||
bold = 1,
|
||||
dim,
|
||||
@@ -38,7 +38,7 @@ fg: Color = .white,
|
||||
bg: Color = .default,
|
||||
ul: Color = .default,
|
||||
ul_style: Underline = .off,
|
||||
attributes: []const Attribute,
|
||||
emphasis: []const Emphasis,
|
||||
|
||||
pub fn eql(this: Style, other: Style) bool {
|
||||
return std.meta.eql(this, other);
|
||||
@@ -60,9 +60,7 @@ pub fn value(this: Style, writer: anytype, cp: u21) !void {
|
||||
try std.fmt.format(writer, ";", .{});
|
||||
try this.ul.write(writer, .ul);
|
||||
// append styles (aka attributes like bold, italic, strikethrough, etc.)
|
||||
for (this.attributes) |attribute| {
|
||||
try std.fmt.format(writer, ";{d}", .{@intFromEnum(attribute)});
|
||||
}
|
||||
for (this.emphasis) |attribute| try std.fmt.format(writer, ";{d}", .{@intFromEnum(attribute)});
|
||||
try std.fmt.format(writer, "m", .{});
|
||||
// content
|
||||
try std.fmt.format(writer, "{s}", .{buffer});
|
||||
|
||||
Reference in New Issue
Block a user