feat(formatters): add window manager formatters

This commit is contained in:
utox39
2025-10-03 12:50:19 +02:00
parent 2f847fbef3
commit d6978cd4b2

View File

@@ -20,6 +20,7 @@ pub const formatters = [_]*const fn (allocator: std.mem.Allocator, key: []const
&getFormattedSwapInfo,
&getFormattedDiskInfo,
&getFormattedNetInfo,
&getFormattedWindowManagerInfo,
&getFormattedTerminalNameInfo,
&getFormattedLocaleInfo,
&getFormattedCustom,
@@ -37,6 +38,7 @@ pub const default_formatters = [_]*const fn (allocator: std.mem.Allocator) anyer
&getDefaultFormattedSwapInfo,
&getDefaultFormattedDiskInfo,
&getDefaultFormattedNetInfo,
&getDefaultFormattedWindowManagerInfo,
&getDefaultFormattedTerminalNameInfo,
&getDefaultFormattedLocaleInfo,
};
@@ -192,6 +194,16 @@ pub fn getFormattedDiskInfo(allocator: std.mem.Allocator, key: []const u8, key_c
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s} ({s}):{s} {d:.2} / {d:.2} GB ({}%)", .{ key_color, key, disk_info.disk_path, ascii.Reset, disk_info.disk_usage, disk_info.disk_size, disk_info.disk_usage_percentage }) };
}
pub fn getDefaultFormattedWindowManagerInfo(allocator: std.mem.Allocator) !Result {
return try getFormattedWindowManagerInfo(allocator, "WM", ascii.Yellow);
}
pub fn getFormattedWindowManagerInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
const wm = try detection.system.getWindowManagerInfo(allocator);
defer allocator.free(wm);
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, wm }) };
}
pub fn getDefaultFormattedTerminalNameInfo(allocator: std.mem.Allocator) !Result {
return try getFormattedTerminalNameInfo(allocator, "Terminal", ascii.Yellow);
}