From abff59b7d69802904d693bff689bcba0afb512a6 Mon Sep 17 00:00:00 2001 From: utox39 Date: Sat, 13 Sep 2025 17:40:53 +0200 Subject: [PATCH 1/6] fix(config): fix null value access when config file are not used --- src/config.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config.zig b/src/config.zig index c081bbd..b06d8a4 100644 --- a/src/config.zig +++ b/src/config.zig @@ -31,7 +31,9 @@ pub const ModuleType = enum { }; pub fn getAsciiPath(config: ?std.json.Parsed(Config)) ?[]u8 { - return config.?.value.ascii_abs_path; + if (config) |c| { + return c.value.ascii_abs_path; + } else return null; } pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.array_list.Managed(ModuleType) { From aab5212e6efd1e1bfc9c17947abd21a73c66d9e5 Mon Sep 17 00:00:00 2001 From: utox39 Date: Sat, 13 Sep 2025 18:33:04 +0200 Subject: [PATCH 2/6] feat(config): add username_hostname_color field and getUsernameHostname function --- src/config.zig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/config.zig b/src/config.zig index b06d8a4..b2c213b 100644 --- a/src/config.zig +++ b/src/config.zig @@ -10,6 +10,7 @@ pub const Module = struct { pub const Config = struct { ascii_abs_path: ?[]u8 = null, + username_hostname_color: ?[]u8 = null, modules: []Module, }; @@ -36,6 +37,12 @@ pub fn getAsciiPath(config: ?std.json.Parsed(Config)) ?[]u8 { } else return null; } +pub fn getUsernameHostnameColor(config: ?std.json.Parsed(Config)) ?[]u8 { + if (config) |c| { + return c.value.username_hostname_color; + } else return null; +} + pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.array_list.Managed(ModuleType) { var modules_list = std.array_list.Managed(ModuleType).init(allocator); From 5f6460f46e9fc2283448ca809a34b7bfd3b47ecc Mon Sep 17 00:00:00 2001 From: utox39 Date: Sat, 13 Sep 2025 18:36:32 +0200 Subject: [PATCH 3/6] feat(formatters): add getFormattedUsernameHostname function --- src/formatters.zig | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/formatters.zig b/src/formatters.zig index c944810..cf466e7 100644 --- a/src/formatters.zig +++ b/src/formatters.zig @@ -41,6 +41,17 @@ pub const default_formatters = [_]*const fn (allocator: std.mem.Allocator) anyer &getDefaultFormattedLocaleInfo, }; +pub fn getFormattedUsernameHostname(allocator: std.mem.Allocator, color: []const u8, username: []const u8, hostname: []const u8) ![]u8 { + return try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{ + color, + username, + ascii.Reset, + color, + hostname, + ascii.Reset, + }); +} + pub fn getDefaultFormattedKernelInfo(allocator: std.mem.Allocator) !Result { return try getFormattedKernelInfo(allocator, "Kernel", ascii.Yellow); } From d9ec3a7de71977581c21d23d94be60bf407e2478 Mon Sep 17 00:00:00 2001 From: utox39 Date: Sat, 13 Sep 2025 18:41:15 +0200 Subject: [PATCH 4/6] feat: add logic for username and hostname colors --- src/main.zig | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main.zig b/src/main.zig index 289dd4a..d7af439 100644 --- a/src/main.zig +++ b/src/main.zig @@ -27,14 +27,15 @@ pub fn main() !void { const username = try detection.user.getUsername(allocator); const hostname = try detection.system.getHostname(allocator); - try modules_list.append(try std.fmt.allocPrint(allocator, "{s}{s}{s}@{s}{s}{s}", .{ - ascii.Yellow, - username, - ascii.Reset, - ascii.Yellow, - hostname, - ascii.Reset, - })); + + const username_hostname_color = if (config.getUsernameHostnameColor(conf)) |color| blk: { + var buf: [32]u8 = undefined; + const rgb = try ascii.hexColorToRgb(color); + const formatted_color = try std.fmt.bufPrint(&buf, "\x1b[38;2;{d};{d};{d}m", .{ rgb.r, rgb.g, rgb.b }); + break :blk formatted_color; + } else ascii.Yellow; + + try modules_list.append(try formatters.getFormattedUsernameHostname(allocator, username_hostname_color, username, hostname)); allocator.free(hostname); allocator.free(username); From a125053c7075bd09ddfcf7250f6cc1bc25c2118c Mon Sep 17 00:00:00 2001 From: utox39 Date: Sat, 13 Sep 2025 19:52:14 +0200 Subject: [PATCH 5/6] refactor(config): remove unused import --- src/config.zig | 1 - 1 file changed, 1 deletion(-) diff --git a/src/config.zig b/src/config.zig index b2c213b..2524335 100644 --- a/src/config.zig +++ b/src/config.zig @@ -1,5 +1,4 @@ const std = @import("std"); -const builtin = @import("builtin"); const ascii = @import("ascii.zig"); pub const Module = struct { From 6a86a81fcc2a0906e41c746179a49c3966d36eb8 Mon Sep 17 00:00:00 2001 From: utox39 Date: Sat, 13 Sep 2025 20:04:27 +0200 Subject: [PATCH 6/6] build: bump version to 0.22.0 --- build.zig.zon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.zig.zon b/build.zig.zon index e00987f..fa15cab 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,7 +10,7 @@ // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. - .version = "0.21.1", + .version = "0.22.0", // Together with name, this represents a globally unique package // identifier. This field is generated by the Zig toolchain when the