From 54cc513fa1a4d8459778886a5672105bc4c482ad Mon Sep 17 00:00:00 2001 From: RadsammyT Date: Wed, 25 Mar 2026 17:42:18 -0400 Subject: [PATCH] Review --- res/config.ini | 2 +- res/lang/en.ini | 6 +++--- src/config/migrator.zig | 1 - src/main.zig | 47 +++++++++++++++++++++++------------------ 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/res/config.ini b/res/config.ini index e65b509..b780fe0 100644 --- a/res/config.ini +++ b/res/config.ini @@ -388,7 +388,7 @@ xsessions = $PREFIX_DIRECTORY/share/xsessions # Comments preceding with '#' comment out the example INI. ##--- -# Declare a command with the F8 binding. +## Declare a command with the F8 binding. #[cmd:F8] ## The name of the command to show up in Ly. ## Note: "$" in "$brightness_up" fetches the appropriate string from the specified locale file diff --git a/res/lang/en.ini b/res/lang/en.ini index 3442c38..b3d40f2 100644 --- a/res/lang/en.ini +++ b/res/lang/en.ini @@ -3,9 +3,9 @@ brightness_down = decrease brightness brightness_up = increase brightness capslock = capslock custom = custom - - - +custom_info_err_output_long = output too long +custom_info_err_no_output = no output +custom_info_err_no_output_error = , possible error err_alloc = failed memory allocation err_args = unable to parse command line arguments err_autologin_session = autologin session not found diff --git a/src/config/migrator.zig b/src/config/migrator.zig index 438a6f7..1c95d51 100644 --- a/src/config/migrator.zig +++ b/src/config/migrator.zig @@ -214,7 +214,6 @@ pub fn configFieldHandler(_: std.mem.Allocator, field: ini.IniField) ?ini.IniFie } if (std.mem.eql(u8, field.key, "refresh")) { label.refresh = std.fmt.parseInt(u32, field.value, 10) catch 0; - label.refresh += 1; } } } diff --git a/src/main.zig b/src/main.zig index 1466aa5..b7ad9c8 100644 --- a/src/main.zig +++ b/src/main.zig @@ -64,9 +64,16 @@ fn ttyControlTransferSignalHandler(_: c_int) callconv(.c) void { TerminalBuffer.shutdown(); } -const CustomBindLabel = struct { cmd: custom.CustomCommandBind, key: []const u8, lbl: Label }; +const CustomBindLabel = struct { + cmd: custom.CustomCommandBind, + key: []const u8, + lbl: Label, +}; -const CustomInfoLabel = struct { info: custom.CustomCommandInfo, lbl: Label }; +const CustomInfoLabel = struct { + info: custom.CustomCommandInfo, + lbl: Label, +}; const UiState = struct { allocator: Allocator, @@ -217,8 +224,7 @@ pub fn main() !void { custom.labels = .init(state.allocator); var config_parser = try IniParser(Config).init(state.allocator, config_path, migrator.configFieldHandler); defer config_parser.deinit(); - defer { - if (!shutdown or !restart) { + defer if (!shutdown or !restart) { var iter = custom.binds.iterator(); while (iter.next()) |i| { temporary_allocator.free(i.key_ptr.*); @@ -233,8 +239,7 @@ pub fn main() !void { temporary_allocator.free(cmd); } custom.labels.deinit(); - } - } + }; state.config = config_parser.structure; @@ -1068,25 +1073,28 @@ pub fn main() !void { // Layer 2 var layer2: std.ArrayList(*Widget) = .empty; - state.custom_binds = .empty; - state.custom_info = .empty; - defer state.custom_binds.deinit(state.allocator); - defer state.custom_info.deinit(state.allocator); defer layer2.deinit(state.allocator); + state.custom_binds = .empty; + defer state.custom_binds.deinit(state.allocator); + + state.custom_info = .empty; + defer state.custom_info.deinit(state.allocator); + var lblIter = custom.labels.iterator(); while (lblIter.next()) |i| { - try state.custom_info.append(state.allocator, .{ .info = i.value_ptr.*, .lbl = .init("", null, state.buffer.fg, state.buffer.bg, &updateCustomInfo, null) }); + try state.custom_info.append(state.allocator, .{ + .info = i.value_ptr.*, + .lbl = .init("", null, state.buffer.fg, state.buffer.bg, &updateCustomInfo, null), + }); var latest = &state.custom_info.items[state.custom_info.items.len - 1]; latest.info.id = latest.lbl.widget().id; - latest.info.counter = 2; + latest.info.counter = 1; } - defer { - for (state.custom_info.items) |*item| { + defer for (state.custom_info.items) |*item| { state.allocator.free(item.lbl.text); item.lbl.deinit(); - } - } + }; var iter = custom.binds.iterator(); while (iter.next()) |i| { @@ -1110,11 +1118,9 @@ pub fn main() !void { }); state.custom_binds.items[state.custom_binds.items.len - 1].lbl.allocator = state.allocator; } - defer { - for (state.custom_binds.items) |*i| { + defer for (state.custom_binds.items) |*i| { i.lbl.deinit(); - } - } + }; if (!state.config.hide_key_hints) { try layer2.append(state.allocator, state.shutdown_label.widget()); @@ -1738,6 +1744,7 @@ fn updateCustomInfo(lbl: *Label, ptr: *anyopaque) !void { const wid = lbl.widget().id; var stdout = std.ArrayList(u8).empty; defer stdout.deinit(state.allocator); + var stderr = std.ArrayList(u8).empty; defer stderr.deinit(state.allocator); for (state.custom_info.items) |*i| {