widgets(table): added support f/ enums and slices of strings

- Added proper printing f/ Enums and Slices of Strings into Table cells.
This commit is contained in:
00JCIV00 2024-08-14 17:58:33 -04:00 committed by Tim Culverhouse
parent 26072bd85e
commit d1b4e3f010

View file

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