mod(style): styling and color revamp now with fewer characters to print to the terminal

This commit is contained in:
2025-02-04 17:51:28 +01:00
parent 2bfacc0e98
commit 9c06ced658
4 changed files with 64 additions and 154 deletions

View File

@@ -5,6 +5,7 @@ const isTaggedUnion = @import("event.zig").isTaggedUnion;
const Cell = @import("cell.zig");
const Color = @import("color.zig").Color;
const Size = @import("size.zig");
const Style = @import("style.zig");
const log = std.log.scoped(.container);
@@ -13,7 +14,7 @@ pub const Border = struct {
pub const rounded_border: [6]u21 = .{ '╭', '─', '╮', '│', '╰', '╯' };
pub const squared_border: [6]u21 = .{ '┌', '─', '┐', '│', '└', '┘' };
/// Color to use for the border
color: Color = .{ .ansi = .reset },
color: Color = .white,
/// Configure the corner type to be used for the border
corners: enum(u1) {
squared,
@@ -29,7 +30,7 @@ pub const Border = struct {
/// Configure separator borders between child element to added to the layout
separator: struct {
enabled: bool = false,
color: Color = .{ .ansi = .reset },
color: Color = .white,
line: enum {
line,
dotted,
@@ -39,6 +40,7 @@ pub const Border = struct {
// NOTE: caller owns `cells` slice and ensures that `cells.len == size.cols * size.rows`
pub fn contents(this: @This(), cells: []Cell, size: Size) void {
log.debug("Content of Border: {any}", .{this});
std.debug.assert(cells.len == size.cols * size.rows);
const frame = switch (this.corners) {
@@ -68,14 +70,16 @@ pub const Border = struct {
cells[last_row + col].cp = frame[1];
}
// TODO: fix rendering of styling?
cells[col].style = .{ .fg = .{ .ansi = .red }, .attributes = &.{} };
cells[last_row + col].style = .{ .fg = .{ .ansi = .red }, .attributes = &.{} };
cells[col].style.fg = this.color;
cells[last_row + col].style.fg = this.color;
}
// render left and right border
for (1..size.rows - 1) |row| {
const idx = (row * size.cols);
cells[idx].cp = frame[3]; // left
cells[idx].style.fg = this.color;
cells[idx + size.cols - 1].cp = frame[3]; // right
cells[idx + size.cols - 1].style.fg = this.color;
}
}
};
@@ -85,7 +89,7 @@ pub const Rectangle = struct {
/// `Color` to use to fill the `Rectangle` with
/// NOTE: used as background color when rendering! such that it renders the
/// children accordingly without removing the coloring of the `Rectangle`
fill: Color = .{ .ansi = .reset },
fill: Color = .black,
/// Configure the corners of the `Rectangle`
corners: enum(u1) {
squared,