From d8a9e72b67e3b20c58859a10582a834e957455bf Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Sun, 16 Feb 2025 02:04:53 +0100 Subject: [PATCH] add(border): seperator line options with corresponding code points --- examples/container.zig | 9 +++++++-- src/container.zig | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/examples/container.zig b/examples/container.zig index 09d3474..a6cc52e 100644 --- a/examples/container.zig +++ b/examples/container.zig @@ -63,11 +63,16 @@ pub fn main() !void { const element = element_wrapper.element(); var container = try App.Container.init(allocator, .{ - .border = .{ .separator = .{ .enabled = true } }, + .border = .{ + .separator = .{ + .enabled = true, + .line = .double, + }, + }, .layout = .{ .gap = 2, .padding = .all(5), - .direction = .horizontal, + .direction = .vertical, }, }, element); var box = try App.Container.init(allocator, .{ diff --git a/src/container.zig b/src/container.zig index eca763c..20d988c 100644 --- a/src/container.zig +++ b/src/container.zig @@ -13,6 +13,9 @@ const log = std.log.scoped(.container); pub const Border = packed struct { pub const rounded_border: [6]u21 = .{ '╭', '─', '╮', '│', '╰', '╯' }; pub const squared_border: [6]u21 = .{ '┌', '─', '┐', '│', '└', '┘' }; + pub const line: [2]u21 = .{ '│', '─' }; + pub const dotted: [2]u21 = .{ '┆', '┄' }; + pub const double: [2]u21 = .{ '║', '═' }; /// Color to use for the border color: Color = .default, /// Configure the corner type to be used for the border @@ -38,10 +41,10 @@ pub const Border = packed struct { separator: packed struct { enabled: bool = false, color: Color = .white, - line: enum(u1) { + line: enum(u2) { line, dotted, - // TODO: add more variations which could be used for the separator + double, } = .line, } = .{}, @@ -126,6 +129,11 @@ pub const Border = packed struct { break :blk rows - element_rows * len; }, }; + const line_cps: [2]u21 = switch (this.separator.line) { + .line => line, + .dotted => dotted, + .double => double, + }; switch (layout.direction) { .horizontal => { offset += layout.gap / 2; @@ -137,8 +145,7 @@ pub const Border = packed struct { } offset += cols; for (1..size.rows -| 1) |row| { - // TODO: support the line options - cells[row * size.cols + offset].cp = frame[3]; + cells[row * size.cols + offset].cp = line_cps[0]; cells[row * size.cols + offset].style.fg = this.separator.color; } offset += layout.gap; @@ -154,8 +161,7 @@ pub const Border = packed struct { } offset += rows; for (1..size.cols -| 1) |col| { - // TODO: support the line options - cells[offset * size.cols + col].cp = frame[1]; + cells[offset * size.cols + col].cp = line_cps[1]; cells[offset * size.cols + col].style.fg = this.separator.color; } offset += layout.gap;