generated from general-packages/pika-pkg-template
GiB to GB
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 47s
All checks were successful
PikaOS Package Build & Release (amd64-v3) / build (push) Successful in 47s
This commit is contained in:
parent
5f616c290b
commit
3863ab5adc
2
.github/release-nest-v3
vendored
2
.github/release-nest-v3
vendored
@ -1 +1 @@
|
||||
1
|
||||
2
|
@ -1,4 +1,4 @@
|
||||
pikafetch (0.3.0-101pika3) pika; urgency=medium
|
||||
pikafetch (0.3.0-101pika4) pika; urgency=medium
|
||||
|
||||
* Multiple disk support, add caching of GPU and packages info
|
||||
|
||||
|
21
pikafetch/src/display/format.zig
Normal file
21
pikafetch/src/display/format.zig
Normal file
@ -0,0 +1,21 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const SizeInfo = struct {
|
||||
value: f64,
|
||||
unit: []const u8,
|
||||
};
|
||||
|
||||
pub fn formatSize(bytes: u64) SizeInfo {
|
||||
const units = [_][]const u8{ "B", "KB", "MB", "GB", "TB", "PB" };
|
||||
var size: f64 = @floatFromInt(bytes);
|
||||
var unit_index: usize = 0;
|
||||
|
||||
while (size >= 1000 and unit_index < units.len - 1) : (unit_index += 1) {
|
||||
size /= 1000;
|
||||
}
|
||||
|
||||
return SizeInfo{
|
||||
.value = size,
|
||||
.unit = units[unit_index],
|
||||
};
|
||||
}
|
@ -3,6 +3,7 @@ const os = std.os;
|
||||
const fs = std.fs;
|
||||
const mem = std.mem;
|
||||
const ArrayList = std.ArrayList;
|
||||
const format = @import("../../display/format.zig");
|
||||
|
||||
pub const DiskInfo = struct {
|
||||
mount_point: []const u8,
|
||||
@ -11,7 +12,6 @@ pub const DiskInfo = struct {
|
||||
fs_type: []const u8,
|
||||
};
|
||||
|
||||
// Comptime array of physical filesystem types
|
||||
const physical_fs = [_][]const u8{
|
||||
"ext4",
|
||||
"btrfs",
|
||||
|
@ -1,10 +1,5 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub const SizeInfo = struct {
|
||||
value: f64,
|
||||
unit: []const u8,
|
||||
};
|
||||
|
||||
pub const MemInfo = struct {
|
||||
total: u64,
|
||||
used: u64,
|
||||
@ -15,21 +10,6 @@ pub const SwapInfo = struct {
|
||||
used: u64,
|
||||
};
|
||||
|
||||
pub fn formatSize(bytes: u64) SizeInfo {
|
||||
const units = [_][]const u8{ "B", "KiB", "MiB", "GiB", "TiB" };
|
||||
var size: f64 = @floatFromInt(bytes);
|
||||
var unit_index: usize = 0;
|
||||
|
||||
while (size >= 1024 and unit_index < units.len - 1) : (unit_index += 1) {
|
||||
size /= 1024;
|
||||
}
|
||||
|
||||
return SizeInfo{
|
||||
.value = size,
|
||||
.unit = units[unit_index],
|
||||
};
|
||||
}
|
||||
|
||||
pub fn getMemoryInfo() !MemInfo {
|
||||
const file = try std.fs.openFileAbsolute("/proc/meminfo", .{});
|
||||
defer file.close();
|
||||
|
@ -11,6 +11,7 @@ const wm = @import("desktop/wm.zig");
|
||||
const terminal = @import("desktop/terminal.zig");
|
||||
const shell = @import("desktop/shell.zig");
|
||||
const motherboard = @import("hardware/motherboard.zig");
|
||||
const format = @import("../display/format.zig");
|
||||
|
||||
pub const SystemInfo = struct {
|
||||
username: []const u8,
|
||||
@ -85,10 +86,10 @@ pub const SystemInfo = struct {
|
||||
mem_percentage: u64,
|
||||
swap_percentage: u64,
|
||||
disk_percentages: []const u64,
|
||||
mem_fmt: memory.SizeInfo,
|
||||
mem_total_fmt: memory.SizeInfo,
|
||||
swap_fmt: memory.SizeInfo,
|
||||
swap_total_fmt: memory.SizeInfo,
|
||||
mem_fmt: format.SizeInfo,
|
||||
mem_total_fmt: format.SizeInfo,
|
||||
swap_fmt: format.SizeInfo,
|
||||
swap_total_fmt: format.SizeInfo,
|
||||
usage_colors: []const []const u8,
|
||||
}{
|
||||
.mem_percentage = @divFloor(self.memory_used * 100, self.memory_total),
|
||||
@ -100,10 +101,10 @@ pub const SystemInfo = struct {
|
||||
}
|
||||
break :blk percentages;
|
||||
},
|
||||
.mem_fmt = memory.formatSize(self.memory_used),
|
||||
.mem_total_fmt = memory.formatSize(self.memory_total),
|
||||
.swap_fmt = memory.formatSize(self.swap_used),
|
||||
.swap_total_fmt = memory.formatSize(self.swap_total),
|
||||
.mem_fmt = format.formatSize(self.memory_used),
|
||||
.mem_total_fmt = format.formatSize(self.memory_total),
|
||||
.swap_fmt = format.formatSize(self.swap_used),
|
||||
.swap_total_fmt = format.formatSize(self.swap_total),
|
||||
.usage_colors = blk: {
|
||||
var colors_array = try output_allocator.alloc([]const u8, 2 + self.disks.len);
|
||||
colors_array[0] = getUsageColor(@divFloor(self.memory_used * 100, self.memory_total));
|
||||
@ -155,8 +156,8 @@ 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);
|
||||
const disk_fmt = format.formatSize(disk_info.used);
|
||||
const disk_total_fmt = format.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,
|
||||
|
Loading…
Reference in New Issue
Block a user