feat: add logic for username and hostname colors

This commit is contained in:
utox39
2025-09-13 18:41:15 +02:00
parent 5f6460f46e
commit d9ec3a7de7

View File

@@ -27,14 +27,15 @@ pub fn main() !void {
const username = try detection.user.getUsername(allocator); const username = try detection.user.getUsername(allocator);
const hostname = try detection.system.getHostname(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, const username_hostname_color = if (config.getUsernameHostnameColor(conf)) |color| blk: {
username, var buf: [32]u8 = undefined;
ascii.Reset, const rgb = try ascii.hexColorToRgb(color);
ascii.Yellow, const formatted_color = try std.fmt.bufPrint(&buf, "\x1b[38;2;{d};{d};{d}m", .{ rgb.r, rgb.g, rgb.b });
hostname, break :blk formatted_color;
ascii.Reset, } else ascii.Yellow;
}));
try modules_list.append(try formatters.getFormattedUsernameHostname(allocator, username_hostname_color, username, hostname));
allocator.free(hostname); allocator.free(hostname);
allocator.free(username); allocator.free(username);