diff --git a/src/config.zig b/src/config.zig index b6ab4f0..b3ad474 100644 --- a/src/config.zig +++ b/src/config.zig @@ -26,6 +26,7 @@ pub const ModuleType = enum { net, terminal, locale, + custom, }; pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.ArrayList(ModuleType) { diff --git a/src/formatters.zig b/src/formatters.zig index 5931087..df58917 100644 --- a/src/formatters.zig +++ b/src/formatters.zig @@ -22,6 +22,7 @@ pub const formatters = [_]*const fn (allocator: std.mem.Allocator, key: []const &getFormattedNetInfo, &getFormattedTerminalNameInfo, &getFormattedLocaleInfo, + &getFormattedCustom, }; pub const default_formatters = [_]*const fn (allocator: std.mem.Allocator) anyerror!Result{ @@ -207,3 +208,7 @@ pub fn getFormattedNetInfo(allocator: std.mem.Allocator, key: []const u8, key_co return Result{ .string_arraylist = formatted_net_info_list }; } + +pub fn getFormattedCustom(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result { + return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ key_color, key, ascii.Reset }) }; +} diff --git a/src/utils.zig b/src/utils.zig index f1075b0..a58144e 100644 --- a/src/utils.zig +++ b/src/utils.zig @@ -62,6 +62,8 @@ pub fn getLongestSysInfoStringLen(strings: []const []const u8) usize { if (ansi_restet_index != null) { // `start` is the index of the last character of the ANSI reset escape sequence + 1 start = ansi_restet_index.? + ansi_reset.len + 1; + + if (start > s.len) continue; } longest_len = @max(longest_len, s[start..].len);