Review part 1

This commit is contained in:
RadsammyT 2026-03-18 08:20:24 -04:00
commit 2e9e814dcb
No known key found for this signature in database
3 changed files with 21 additions and 18 deletions

View file

@ -76,16 +76,19 @@ pub fn CyclableLabel(comptime ItemType: type, comptime ChangeItemType: type) typ
pub fn positionX(self: *Self, original_pos: Position) void {
self.component_pos = original_pos;
self.cursor = self.component_pos.x + 2;
self.children_pos = original_pos.addX(self.width);
}
pub fn positionY(self: *Self, original_pos: Position) void {
self.component_pos = original_pos;
self.cursor = self.component_pos.x + 2;
self.children_pos = original_pos.addY(1);
}
pub fn positionXY(self: *Self, original_pos: Position) void {
self.component_pos = original_pos;
self.cursor = self.component_pos.x + 2;
self.children_pos = Position.init(
self.width,
1,

View file

@ -2,16 +2,16 @@ const std = @import("std");
const custom = @This();
pub const customCommandBind = struct {
name: []const u8 = undefined,
cmd: []const u8 = undefined,
pub const CustomCommandBind = struct {
name: []const u8 = "",
cmd: []const u8 = "",
posX: u32 = 0,
posY: u32 = 0,
};
pub const UNDEFINED_CMD: []const u8 = "echo \"You forgot to define 'cmd'!\"";
pub const customCommandInfo = struct {
pub const CustomCommandInfo = struct {
name: []const u8 = "",
cmd: []const u8 = UNDEFINED_CMD,
/// To be set to the label widget's `lid`
@ -27,5 +27,5 @@ pub const customCommandInfo = struct {
invertX: bool = false,
};
pub var binds: std.StringHashMap(customCommandBind) = undefined;
pub var labels: std.StringHashMap(customCommandInfo) = undefined;
pub var binds: std.StringHashMap(CustomCommandBind) = undefined;
pub var labels: std.StringHashMap(CustomCommandInfo) = undefined;

View file

@ -38,7 +38,7 @@ const Lang = @import("config/Lang.zig");
const migrator = @import("config/migrator.zig");
const OldSave = @import("config/OldSave.zig");
const SavedUsers = @import("config/SavedUsers.zig");
const CustomCommands = @import("config/custom.zig");
const custom = @import("config/custom.zig");
const DisplayServer = @import("enums.zig").DisplayServer;
const Environment = @import("Environment.zig");
const Entry = Environment.Entry;
@ -65,13 +65,13 @@ fn ttyControlTransferSignalHandler(_: c_int) callconv(.c) void {
}
const CustomBindLabel = struct {
cmd: CustomCommands.customCommandBind,
cmd: custom.CustomCommandBind,
key: []const u8,
lbl: Label
};
const CustomInfoLabel = struct {
info: CustomCommands.customCommandInfo,
info: custom.CustomCommandInfo,
lbl: Label
};
@ -220,27 +220,27 @@ pub fn main() !void {
const config_path = try std.fs.path.join(state.allocator, &[_][]const u8{ config_parent_path, "config.ini" });
defer state.allocator.free(config_path);
CustomCommands.binds = .init(state.allocator);
CustomCommands.labels = .init(state.allocator);
custom.binds = .init(state.allocator);
custom.labels = .init(state.allocator);
var config_parser = try IniParser(Config).init(state.allocator, config_path, migrator.configFieldHandler);
defer config_parser.deinit();
// mapping.deinit() has to be done here
defer {
if (!shutdown or !restart) {
var iter = CustomCommands.binds.iterator();
var iter = custom.binds.iterator();
while (iter.next()) |i| {
temporary_allocator.free(i.key_ptr.*);
temporary_allocator.free(i.value_ptr.*.cmd);
temporary_allocator.free(i.value_ptr.*.name);
}
CustomCommands.binds.deinit();
var labelIter = CustomCommands.labels.iterator();
custom.binds.deinit();
var labelIter = custom.labels.iterator();
while (labelIter.next()) |i| {
temporary_allocator.free(i.key_ptr.*);
if (i.value_ptr.cmd.ptr != CustomCommands.UNDEFINED_CMD.ptr)
if (i.value_ptr.cmd.ptr != custom.UNDEFINED_CMD.ptr)
temporary_allocator.free(i.value_ptr.*.cmd);
}
CustomCommands.labels.deinit();
custom.labels.deinit();
}
}
@ -1081,7 +1081,7 @@ pub fn main() !void {
defer state.custom_info.deinit(state.allocator);
defer layer2.deinit(state.allocator);
var lblIter = CustomCommands.labels.iterator();
var lblIter = custom.labels.iterator();
while (lblIter.next()) |i| {
const w = Label.init("",
null,
@ -1104,7 +1104,7 @@ pub fn main() !void {
}
}
var iter = CustomCommands.binds.iterator();
var iter = custom.binds.iterator();
while (iter.next()) |i| {
var concat = try std.mem.concat(state.allocator, u8,
&[_][]const u8{