Add widget display name to improve logging

Signed-off-by: AnErrupTion <anerruption@disroot.org>
This commit is contained in:
AnErrupTion
2026-02-11 21:51:07 +01:00
parent b389e379fa
commit 6773f74788
15 changed files with 22 additions and 19 deletions

View File

@@ -25,6 +25,7 @@ pub fn init(
pub fn widget(self: *Cascade) Widget {
return Widget.init(
"Cascade",
self,
null,
null,

View File

@@ -55,6 +55,7 @@ pub fn init(
pub fn widget(self: *ColorMix) Widget {
return Widget.init(
"ColorMix",
self,
null,
null,

View File

@@ -62,6 +62,7 @@ pub fn init(
pub fn widget(self: *Doom) Widget {
return Widget.init(
"Doom",
self,
deinit,
realloc,

View File

@@ -417,6 +417,7 @@ pub fn init(
pub fn widget(self: *DurFile) Widget {
return Widget.init(
"DurFile",
self,
deinit,
realloc,

View File

@@ -72,6 +72,7 @@ pub fn init(
pub fn widget(self: *GameOfLife) Widget {
return Widget.init(
"GameOfLife",
self,
deinit,
realloc,

View File

@@ -69,6 +69,7 @@ pub fn init(
pub fn widget(self: *Matrix) Widget {
return Widget.init(
"Matrix",
self,
deinit,
realloc,

View File

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

View File

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

View File

@@ -84,6 +84,7 @@ pub fn deinit(self: *BigLabel) void {
pub fn widget(self: *BigLabel) Widget {
return Widget.init(
"BigLabel",
self,
deinit,
null,

View File

@@ -61,6 +61,7 @@ pub fn init(
pub fn widget(self: *CenteredBox) Widget {
return Widget.init(
"CenteredBox",
self,
null,
null,

View File

@@ -47,6 +47,7 @@ pub fn deinit(self: *InfoLine) void {
pub fn widget(self: *InfoLine) Widget {
return Widget.init(
"InfoLine",
self,
deinit,
null,

View File

@@ -42,6 +42,7 @@ pub fn deinit(self: *Label) void {
pub fn widget(self: *Label) Widget {
return Widget.init(
"Label",
self,
deinit,
null,

View File

@@ -57,6 +57,7 @@ pub fn deinit(self: *Session) void {
pub fn widget(self: *Session) Widget {
return Widget.init(
"Session",
self,
deinit,
null,

View File

@@ -56,6 +56,7 @@ pub fn deinit(self: *Text) void {
pub fn widget(self: *Text) Widget {
return Widget.init(
"Text",
self,
deinit,
null,

View File

@@ -89,6 +89,7 @@ pub fn deinit(self: *UserList) void {
pub fn widget(self: *UserList) Widget {
return Widget.init(
"UserList",
self,
deinit,
null,