Bump version to 0.3.0-101pika3, add filesystem type support for disks, and update system info formatting to include memory and swap usage
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 52s

This commit is contained in:
ferreo 2024-12-01 19:39:30 +00:00
parent 669f110ff6
commit 5f616c290b
4 changed files with 29 additions and 22 deletions

View File

@ -1 +1 @@
2
1

View File

@ -1,4 +1,4 @@
pikafetch (0.3.0-101pika2) pika; urgency=medium
pikafetch (0.3.0-101pika3) pika; urgency=medium
* Multiple disk support, add caching of GPU and packages info

View File

@ -8,6 +8,7 @@ pub const DiskInfo = struct {
mount_point: []const u8,
total: u64,
used: u64,
fs_type: []const u8,
};
// Comptime array of physical filesystem types
@ -21,6 +22,8 @@ const physical_fs = [_][]const u8{
"zfs",
"bcachefs",
"vfat",
"ntfs",
"exfat",
};
fn isPhysicalFS(fs_type: []const u8) bool {
@ -57,6 +60,7 @@ pub fn getDisksInfo(allocator: mem.Allocator) ![]DiskInfo {
.mount_point = try allocator.dupe(u8, mount_point),
.total = info.total,
.used = info.used,
.fs_type = try allocator.dupe(u8, fs_type),
});
}
@ -94,5 +98,6 @@ pub fn getDiskInfo(mount_point: []const u8) !DiskInfo {
.mount_point = mount_point,
.total = total,
.used = used,
.fs_type = "",
};
}

View File

@ -17,7 +17,6 @@ pub const SystemInfo = struct {
hostname: []const u8,
os_name: []const u8,
kernel: []const u8,
uptime: u64,
memory_total: u64,
memory_used: u64,
host: []const u8,
@ -64,7 +63,6 @@ pub const SystemInfo = struct {
.hostname = hostname_str.?,
.os_name = os_name.?,
.kernel = kernel_ver.?,
.uptime = 0,
.memory_total = mem_info.total,
.memory_used = mem_info.used,
.host = host.?,
@ -123,7 +121,7 @@ pub const SystemInfo = struct {
try std.fmt.allocPrint(output_allocator, "{s}OS:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.os_name }),
try std.fmt.allocPrint(output_allocator, "{s}Host:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.host }),
try std.fmt.allocPrint(output_allocator, "{s}Kernel:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.kernel }),
try std.fmt.allocPrint(output_allocator, "{s}Packages:{s} {d} (dpkg)", .{ colors.Color.bold, colors.Color.reset, self.packages }),
try std.fmt.allocPrint(output_allocator, "{s}Packages:{s} {d} (native)", .{ colors.Color.bold, colors.Color.reset, self.packages }),
try std.fmt.allocPrint(output_allocator, "{s}Shell:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.shell_name }),
try std.fmt.allocPrint(output_allocator, "{s}WM:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.wm }),
try std.fmt.allocPrint(output_allocator, "{s}Terminal:{s} {s}", .{ colors.Color.bold, colors.Color.reset, self.terminal }),
@ -139,23 +137,6 @@ pub const SystemInfo = struct {
}));
}
for (self.disks, 0..) |disk_info, i| {
const disk_fmt = memory.formatSize(disk_info.used);
const disk_total_fmt = memory.formatSize(disk_info.total);
try info.append(try std.fmt.allocPrint(output_allocator, "{s}Disk {s}:{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s})", .{
colors.Color.bold,
disk_info.mount_point,
colors.Color.reset,
disk_fmt.value,
disk_fmt.unit,
disk_total_fmt.value,
disk_total_fmt.unit,
calculations.usage_colors[2 + i],
calculations.disk_percentages[i],
colors.Color.reset,
}));
}
try info.appendSlice(&[_][]const u8{
try std.fmt.allocPrint(output_allocator, "{s}Memory:{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s})", .{
colors.Color.bold, colors.Color.reset,
@ -171,6 +152,27 @@ pub const SystemInfo = struct {
calculations.usage_colors[1], calculations.swap_percentage,
colors.Color.reset,
}),
});
for (self.disks, 0..) |disk_info, i| {
const disk_fmt = memory.formatSize(disk_info.used);
const disk_total_fmt = memory.formatSize(disk_info.total);
try info.append(try std.fmt.allocPrint(output_allocator, "{s}{s}:{s} {d:.2} {s} / {d:.2} {s} ({s}{d}%{s}) - {s}", .{
colors.Color.bold,
disk_info.mount_point,
colors.Color.reset,
disk_fmt.value,
disk_fmt.unit,
disk_total_fmt.value,
disk_total_fmt.unit,
calculations.usage_colors[2 + i],
calculations.disk_percentages[i],
colors.Color.reset,
disk_info.fs_type,
}));
}
try info.appendSlice(&[_][]const u8{
try std.fmt.allocPrint(output_allocator, "", .{}),
try std.fmt.allocPrint(output_allocator, "\x1b[30m███\x1b[31m███\x1b[32m███\x1b[33m███\x1b[34m███\x1b[35m███\x1b[36m███\x1b[37m███{s}", .{
colors.Color.reset,