From d1b4e3f010aa25631df0c5bcfdbd2abc3063d18c Mon Sep 17 00:00:00 2001 From: 00JCIV00 Date: Wed, 14 Aug 2024 17:58:33 -0400 Subject: [PATCH] widgets(table): added support f/ enums and slices of strings - Added proper printing f/ Enums and Slices of Strings into Table cells. --- src/widgets/Table.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/widgets/Table.zig b/src/widgets/Table.zig index e42fa92..ca85df7 100644 --- a/src/widgets/Table.zig +++ b/src/widgets/Table.zig @@ -232,12 +232,20 @@ pub fn drawTable( }); const item_txt = switch (ItemT) { []const u8 => item, + [][]const u8, []const []const u8 => strSlice: { + if (alloc) |_alloc| break :strSlice try fmt.allocPrint(_alloc, "{s}", .{ item }); + break :strSlice item; + }, else => nonStr: { switch (@typeInfo(ItemT)) { + .Enum => break :nonStr @tagName(item), .Optional => { const opt_item = item orelse break :nonStr "-"; switch (@typeInfo(ItemT).Optional.child) { []const u8 => break :nonStr opt_item, + [][]const u8, []const []const u8 => { + break :nonStr if (alloc) |_alloc| try fmt.allocPrint(_alloc, "{s}", .{ opt_item }) else fmt.comptimePrint("[unsupported ({s})]", .{@typeName(DataT)}); + }, else => { break :nonStr if (alloc) |_alloc| try fmt.allocPrint(_alloc, "{any}", .{opt_item}) else fmt.comptimePrint("[unsupported ({s})]", .{@typeName(DataT)}); },