From 6773f7478838aa17848eafd87f556f30de9b0994 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Wed, 11 Feb 2026 21:51:07 +0100 Subject: [PATCH] Add widget display name to improve logging Signed-off-by: AnErrupTion --- src/animations/Cascade.zig | 1 + src/animations/ColorMix.zig | 1 + src/animations/Doom.zig | 1 + src/animations/DurFile.zig | 1 + src/animations/GameOfLife.zig | 1 + src/animations/Matrix.zig | 1 + src/main.zig | 25 ++++++------------------- src/tui/Widget.zig | 3 +++ src/tui/components/BigLabel.zig | 1 + src/tui/components/CenteredBox.zig | 1 + src/tui/components/InfoLine.zig | 1 + src/tui/components/Label.zig | 1 + src/tui/components/Session.zig | 1 + src/tui/components/Text.zig | 1 + src/tui/components/UserList.zig | 1 + 15 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/animations/Cascade.zig b/src/animations/Cascade.zig index 06cfdfe..2ec2452 100644 --- a/src/animations/Cascade.zig +++ b/src/animations/Cascade.zig @@ -25,6 +25,7 @@ pub fn init( pub fn widget(self: *Cascade) Widget { return Widget.init( + "Cascade", self, null, null, diff --git a/src/animations/ColorMix.zig b/src/animations/ColorMix.zig index 206986e..01c9cbe 100644 --- a/src/animations/ColorMix.zig +++ b/src/animations/ColorMix.zig @@ -55,6 +55,7 @@ pub fn init( pub fn widget(self: *ColorMix) Widget { return Widget.init( + "ColorMix", self, null, null, diff --git a/src/animations/Doom.zig b/src/animations/Doom.zig index a657dbc..1bd4dba 100644 --- a/src/animations/Doom.zig +++ b/src/animations/Doom.zig @@ -62,6 +62,7 @@ pub fn init( pub fn widget(self: *Doom) Widget { return Widget.init( + "Doom", self, deinit, realloc, diff --git a/src/animations/DurFile.zig b/src/animations/DurFile.zig index 9ed9207..24a268e 100644 --- a/src/animations/DurFile.zig +++ b/src/animations/DurFile.zig @@ -417,6 +417,7 @@ pub fn init( pub fn widget(self: *DurFile) Widget { return Widget.init( + "DurFile", self, deinit, realloc, diff --git a/src/animations/GameOfLife.zig b/src/animations/GameOfLife.zig index d90590c..32390c1 100644 --- a/src/animations/GameOfLife.zig +++ b/src/animations/GameOfLife.zig @@ -72,6 +72,7 @@ pub fn init( pub fn widget(self: *GameOfLife) Widget { return Widget.init( + "GameOfLife", self, deinit, realloc, diff --git a/src/animations/Matrix.zig b/src/animations/Matrix.zig index 25ff6d1..1cb9c29 100644 --- a/src/animations/Matrix.zig +++ b/src/animations/Matrix.zig @@ -69,6 +69,7 @@ pub fn init( pub fn widget(self: *Matrix) Widget { return Widget.init( + "Matrix", self, deinit, realloc, diff --git a/src/main.zig b/src/main.zig index 71a410b..b0bdced 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1133,8 +1133,8 @@ pub fn main() !void { ); try state.log_file.err( "tui", - "failed to set cursor in active widget: {s}", - .{@errorName(err)}, + "failed to set cursor in active widget '{s}': {s}", + .{ current_widget.display_name, @errorName(err) }, ); }; @@ -1213,19 +1213,6 @@ pub fn main() !void { try state.log_file.info("tui", "screen resolution updated to {d}x{d}", .{ state.buffer.width, state.buffer.height }); - if (animation) |*a| a.realloc() catch |err| { - try state.info_line.addMessage( - state.lang.err_alloc, - state.config.error_bg, - state.config.error_fg, - ); - try state.log_file.err( - "tui", - "failed to reallocate animation buffers: {s}", - .{@errorName(err)}, - ); - }; - for (widgets.items) |*widget| { widget.realloc() catch |err| { try state.info_line.addMessage( @@ -1235,8 +1222,8 @@ pub fn main() !void { ); try state.log_file.err( "tui", - "failed to reallocate widget: {s}", - .{@errorName(err)}, + "failed to reallocate widget '{s}': {s}", + .{ widget.display_name, @errorName(err) }, ); }; } @@ -1265,8 +1252,8 @@ pub fn main() !void { ); try state.log_file.err( "tui", - "failed to handle active widget: {s}", - .{@errorName(err)}, + "failed to handle active widget '{s}': {s}", + .{ current_widget.display_name, @errorName(err) }, ); }; } diff --git a/src/tui/Widget.zig b/src/tui/Widget.zig index 80413a7..dc9b609 100644 --- a/src/tui/Widget.zig +++ b/src/tui/Widget.zig @@ -12,10 +12,12 @@ const VTable = struct { }; id: u64, +display_name: []const u8, pointer: *anyopaque, vtable: VTable, pub fn init( + display_name: []const u8, pointer: anytype, comptime deinit_fn: ?fn (ptr: @TypeOf(pointer)) void, comptime realloc_fn: ?fn (ptr: @TypeOf(pointer)) anyerror!void, @@ -86,6 +88,7 @@ pub fn init( return .{ .id = @intFromPtr(Impl.vtable.draw_fn), + .display_name = display_name, .pointer = pointer, .vtable = Impl.vtable, }; diff --git a/src/tui/components/BigLabel.zig b/src/tui/components/BigLabel.zig index 625647f..934102e 100644 --- a/src/tui/components/BigLabel.zig +++ b/src/tui/components/BigLabel.zig @@ -84,6 +84,7 @@ pub fn deinit(self: *BigLabel) void { pub fn widget(self: *BigLabel) Widget { return Widget.init( + "BigLabel", self, deinit, null, diff --git a/src/tui/components/CenteredBox.zig b/src/tui/components/CenteredBox.zig index fd46057..1e69be5 100644 --- a/src/tui/components/CenteredBox.zig +++ b/src/tui/components/CenteredBox.zig @@ -61,6 +61,7 @@ pub fn init( pub fn widget(self: *CenteredBox) Widget { return Widget.init( + "CenteredBox", self, null, null, diff --git a/src/tui/components/InfoLine.zig b/src/tui/components/InfoLine.zig index e3d9904..c8d51b7 100644 --- a/src/tui/components/InfoLine.zig +++ b/src/tui/components/InfoLine.zig @@ -47,6 +47,7 @@ pub fn deinit(self: *InfoLine) void { pub fn widget(self: *InfoLine) Widget { return Widget.init( + "InfoLine", self, deinit, null, diff --git a/src/tui/components/Label.zig b/src/tui/components/Label.zig index fb95a98..7f5015d 100644 --- a/src/tui/components/Label.zig +++ b/src/tui/components/Label.zig @@ -42,6 +42,7 @@ pub fn deinit(self: *Label) void { pub fn widget(self: *Label) Widget { return Widget.init( + "Label", self, deinit, null, diff --git a/src/tui/components/Session.zig b/src/tui/components/Session.zig index 00782b0..81460c0 100644 --- a/src/tui/components/Session.zig +++ b/src/tui/components/Session.zig @@ -57,6 +57,7 @@ pub fn deinit(self: *Session) void { pub fn widget(self: *Session) Widget { return Widget.init( + "Session", self, deinit, null, diff --git a/src/tui/components/Text.zig b/src/tui/components/Text.zig index 23dec80..7e04d09 100644 --- a/src/tui/components/Text.zig +++ b/src/tui/components/Text.zig @@ -56,6 +56,7 @@ pub fn deinit(self: *Text) void { pub fn widget(self: *Text) Widget { return Widget.init( + "Text", self, deinit, null, diff --git a/src/tui/components/UserList.zig b/src/tui/components/UserList.zig index d053623..f4d9179 100644 --- a/src/tui/components/UserList.zig +++ b/src/tui/components/UserList.zig @@ -89,6 +89,7 @@ pub fn deinit(self: *UserList) void { pub fn widget(self: *UserList) Widget { return Widget.init( + "UserList", self, deinit, null,