Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b3c29e22d | ||
|
|
a866952f86 | ||
|
|
5d7bdd8041 | ||
|
|
635dfe00db | ||
|
|
064e8e9597 | ||
|
|
785915d833 | ||
|
|
e492443a2c | ||
|
|
f1bebb08e9 | ||
|
|
f3af8712d2 | ||
|
|
67a2e19ac4 | ||
|
|
2de5047eb7 | ||
|
|
e88586c47a | ||
|
|
28f94d87ed | ||
|
|
0d7f606b7d | ||
|
|
ec0e3ffd18 | ||
|
|
f73b1be023 | ||
|
|
3a5a268bbe | ||
|
|
bdf4a3f7d7 | ||
|
|
68cc541575 | ||
|
|
e28a3b96e5 | ||
|
|
01ad39c0b5 | ||
|
|
a18fd7ade8 | ||
|
|
3e14691e14 |
@@ -18,7 +18,7 @@ Zigfetch is a minimal [neofetch](https://github.com/dylanaraps/neofetch)/[fastfe
|
|||||||
|
|
||||||
### Linux only
|
### Linux only
|
||||||
|
|
||||||
- [libpci](https://github.com/pciutils/pciutils) (linux only)
|
- [libpci](https://github.com/pciutils/pciutils)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
// This is a [Semantic Version](https://semver.org/).
|
// This is a [Semantic Version](https://semver.org/).
|
||||||
// In a future version of Zig it will be used for package deduplication.
|
// In a future version of Zig it will be used for package deduplication.
|
||||||
.version = "0.6.0",
|
.version = "0.7.4",
|
||||||
|
|
||||||
// Together with name, this represents a globally unique package
|
// Together with name, this represents a globally unique package
|
||||||
// identifier. This field is generated by the Zig toolchain when the
|
// identifier. This field is generated by the Zig toolchain when the
|
||||||
|
|||||||
@@ -105,11 +105,13 @@ pub fn printAscii(allocator: std.mem.Allocator, sys_info_list: std.ArrayList([]u
|
|||||||
if (i < sys_info_len) {
|
if (i < sys_info_len) {
|
||||||
try stdout.print("{s}\n", .{sys_info_items[i]});
|
try stdout.print("{s}\n", .{sys_info_items[i]});
|
||||||
} else if (i == sys_info_len + 1) {
|
} else if (i == sys_info_len + 1) {
|
||||||
|
// Print the first row of colors
|
||||||
for (0..8) |j| {
|
for (0..8) |j| {
|
||||||
try stdout.print("\x1b[48;5;{d}m \x1b[0m", .{j});
|
try stdout.print("\x1b[48;5;{d}m \x1b[0m", .{j});
|
||||||
}
|
}
|
||||||
try stdout.print("\n", .{});
|
try stdout.print("\n", .{});
|
||||||
} else if (i == sys_info_len + 2) {
|
} else if (i == sys_info_len + 2) {
|
||||||
|
// Print the second row of colors
|
||||||
for (8..16) |j| {
|
for (8..16) |j| {
|
||||||
try stdout.print("\x1b[48;5;{d}m \x1b[0m", .{j});
|
try stdout.print("\x1b[48;5;{d}m \x1b[0m", .{j});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ pub const ModuleType = enum {
|
|||||||
ram,
|
ram,
|
||||||
swap,
|
swap,
|
||||||
disk,
|
disk,
|
||||||
|
net,
|
||||||
terminal,
|
terminal,
|
||||||
locale,
|
locale,
|
||||||
net, // It must always be the last element of this array
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.ArrayList(ModuleType) {
|
pub fn getModulesTypes(allocator: std.mem.Allocator, config: ?std.json.Parsed(Config)) !std.ArrayList(ModuleType) {
|
||||||
|
|||||||
@@ -124,21 +124,28 @@ pub fn getDefaultFormattedGpuInfo(allocator: std.mem.Allocator) !Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getFormattedGpuInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
pub fn getFormattedGpuInfo(allocator: std.mem.Allocator, key: []const u8, key_color: []const u8) !Result {
|
||||||
var formatted_gpu_info = std.ArrayList([]u8).init(allocator);
|
|
||||||
|
|
||||||
if (builtin.os.tag == .macos) {
|
if (builtin.os.tag == .macos) {
|
||||||
const gpu_info = try detection.hardware.getGpuInfo(allocator);
|
const gpu_info = try detection.hardware.getGpuInfo(allocator);
|
||||||
defer allocator.free(gpu_info.gpu_name);
|
defer allocator.free(gpu_info.gpu_name);
|
||||||
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, ascii.Reset, gpu_info.gpu_name, gpu_info.gpu_cores, gpu_info.gpu_freq }) };
|
return Result{ .string = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, ascii.Reset, gpu_info.gpu_name, gpu_info.gpu_cores, gpu_info.gpu_freq }) };
|
||||||
} else if (builtin.os.tag == .linux) {
|
} else if (builtin.os.tag == .linux) {
|
||||||
|
var formatted_gpu_info_list = std.ArrayList([]u8).init(allocator);
|
||||||
|
|
||||||
const gpu_info_list = try detection.hardware.getGpuInfo(allocator);
|
const gpu_info_list = try detection.hardware.getGpuInfo(allocator);
|
||||||
|
|
||||||
for (gpu_info_list.items) |g| {
|
for (gpu_info_list.items) |g| {
|
||||||
try formatted_gpu_info.append(try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, ascii.Reset, g.gpu_name, g.gpu_cores, g.gpu_freq }));
|
var formatted_gpu_info: []u8 = undefined;
|
||||||
|
if ((g.gpu_cores == 0) or (g.gpu_freq == 0.0)) {
|
||||||
|
formatted_gpu_info = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s}", .{ key_color, key, ascii.Reset, g.gpu_name });
|
||||||
|
} else {
|
||||||
|
formatted_gpu_info = try std.fmt.allocPrint(allocator, "{s}{s}:{s} {s} ({}) @ {d:.2} GHz", .{ key_color, key, ascii.Reset, g.gpu_name, g.gpu_cores, g.gpu_freq });
|
||||||
|
}
|
||||||
|
try formatted_gpu_info_list.append(formatted_gpu_info);
|
||||||
allocator.free(g.gpu_name);
|
allocator.free(g.gpu_name);
|
||||||
}
|
}
|
||||||
gpu_info_list.deinit();
|
gpu_info_list.deinit();
|
||||||
|
|
||||||
return Result{ .string_arraylist = formatted_gpu_info };
|
return Result{ .string_arraylist = formatted_gpu_info_list };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ pub fn getCpuInfo(allocator: std.mem.Allocator) !CpuInfo {
|
|||||||
|
|
||||||
// Parsing /proc/cpuinfo
|
// Parsing /proc/cpuinfo
|
||||||
var model_name: ?[]const u8 = null;
|
var model_name: ?[]const u8 = null;
|
||||||
|
var cpu_max_freq_mhz_str: ?[]const u8 = null;
|
||||||
|
|
||||||
var lines = std.mem.splitScalar(u8, cpuinfo_data, '\n');
|
var lines = std.mem.splitScalar(u8, cpuinfo_data, '\n');
|
||||||
while (lines.next()) |line| {
|
while (lines.next()) |line| {
|
||||||
@@ -60,14 +61,36 @@ pub fn getCpuInfo(allocator: std.mem.Allocator) !CpuInfo {
|
|||||||
_ = parts.next(); // discards the key
|
_ = parts.next(); // discards the key
|
||||||
if (parts.next()) |value| {
|
if (parts.next()) |value| {
|
||||||
model_name = std.mem.trim(u8, value, " ");
|
model_name = std.mem.trim(u8, value, " ");
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
} else if (std.mem.startsWith(u8, trimmed, "cpu MHz") and cpu_max_freq_mhz_str == null) {
|
||||||
|
var parts = std.mem.splitScalar(u8, trimmed, ':');
|
||||||
|
_ = parts.next(); // discard the key
|
||||||
|
if (parts.next()) |value| {
|
||||||
|
cpu_max_freq_mhz_str = std.mem.trim(u8, value, " ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
|
if ((model_name != null) and (cpu_max_freq_mhz_str != null)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var cpu_max_freq: f32 = 0.0;
|
||||||
|
|
||||||
const cpuinfo_max_freq_path = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
|
const cpuinfo_max_freq_path = "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
|
||||||
|
var cmf_exists: bool = true;
|
||||||
|
|
||||||
|
// Checks if /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq exists
|
||||||
|
_ = std.fs.accessAbsolute(cpuinfo_max_freq_path, .{ .mode = .read_only }) catch |err| {
|
||||||
|
if (err == std.posix.AccessError.FileNotFound) {
|
||||||
|
cmf_exists = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (cmf_exists) {
|
||||||
|
// Reads /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
|
||||||
var file2 = try std.fs.cwd().openFile(cpuinfo_max_freq_path, .{});
|
var file2 = try std.fs.cwd().openFile(cpuinfo_max_freq_path, .{});
|
||||||
|
|
||||||
defer file2.close();
|
defer file2.close();
|
||||||
const cpuinfo_max_freq_data = try file2.readToEndAlloc(allocator, std.math.maxInt(usize));
|
const cpuinfo_max_freq_data = try file2.readToEndAlloc(allocator, std.math.maxInt(usize));
|
||||||
defer allocator.free(cpuinfo_max_freq_data);
|
defer allocator.free(cpuinfo_max_freq_data);
|
||||||
@@ -75,7 +98,13 @@ pub fn getCpuInfo(allocator: std.mem.Allocator) !CpuInfo {
|
|||||||
// Parsing /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
|
// Parsing /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq
|
||||||
const trimmed = std.mem.trim(u8, cpuinfo_max_freq_data, " \n\r");
|
const trimmed = std.mem.trim(u8, cpuinfo_max_freq_data, " \n\r");
|
||||||
const cpu_max_freq_khz: f32 = try std.fmt.parseFloat(f32, trimmed);
|
const cpu_max_freq_khz: f32 = try std.fmt.parseFloat(f32, trimmed);
|
||||||
const cpu_max_freq: f32 = cpu_max_freq_khz / 1_000_000;
|
cpu_max_freq = cpu_max_freq_khz / 1_000_000;
|
||||||
|
} else {
|
||||||
|
if (cpu_max_freq_mhz_str != null) {
|
||||||
|
const cpu_max_freq_mhz: f32 = try std.fmt.parseFloat(f32, cpu_max_freq_mhz_str.?);
|
||||||
|
cpu_max_freq = cpu_max_freq_mhz / 1_000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return CpuInfo{
|
return CpuInfo{
|
||||||
.cpu_name = try allocator.dupe(u8, model_name orelse "Unknown"),
|
.cpu_name = try allocator.dupe(u8, model_name orelse "Unknown"),
|
||||||
@@ -114,8 +143,20 @@ pub fn getGpuInfo(allocator: std.mem.Allocator) !std.ArrayList(GpuInfo) {
|
|||||||
devices.*.device_id,
|
devices.*.device_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const gpu_name = try allocator.dupe(u8, std.mem.span(name));
|
||||||
|
|
||||||
|
const maybe_parsed_gpu_name = try parseGpuName(allocator, gpu_name);
|
||||||
|
var parsed_gpu_name: []u8 = undefined;
|
||||||
|
|
||||||
|
if (maybe_parsed_gpu_name != null) {
|
||||||
|
allocator.free(gpu_name);
|
||||||
|
parsed_gpu_name = maybe_parsed_gpu_name.?;
|
||||||
|
} else {
|
||||||
|
parsed_gpu_name = gpu_name;
|
||||||
|
}
|
||||||
|
|
||||||
try gpu_info_list.append(GpuInfo{
|
try gpu_info_list.append(GpuInfo{
|
||||||
.gpu_name = try allocator.dupe(u8, std.mem.span(name)),
|
.gpu_name = parsed_gpu_name,
|
||||||
.gpu_cores = 0,
|
.gpu_cores = 0,
|
||||||
.gpu_freq = 0.0,
|
.gpu_freq = 0.0,
|
||||||
});
|
});
|
||||||
@@ -133,6 +174,32 @@ pub fn getGpuInfo(allocator: std.mem.Allocator) !std.ArrayList(GpuInfo) {
|
|||||||
return gpu_info_list;
|
return gpu_info_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parseGpuName(allocator: std.mem.Allocator, name: []u8) !?[]u8 {
|
||||||
|
// NOTE: for references: https://github.com/pciutils/pciutils/blob/master/pci.ids
|
||||||
|
|
||||||
|
if (std.mem.startsWith(u8, name, "Advanced Micro Devices, Inc. [AMD/ATI]")) {
|
||||||
|
const size = std.mem.replacementSize(u8, name, "Advanced Micro Devices, Inc. [AMD/ATI]", "AMD");
|
||||||
|
const parsed_gpu_name = try allocator.alloc(u8, size);
|
||||||
|
_ = std.mem.replace(u8, name, "Advanced Micro Devices, Inc. [AMD/ATI]", "AMD", parsed_gpu_name);
|
||||||
|
|
||||||
|
return parsed_gpu_name;
|
||||||
|
} else if (std.mem.startsWith(u8, name, "Intel Corporation")) {
|
||||||
|
const size = std.mem.replacementSize(u8, name, "Intel Corporation", "Intel");
|
||||||
|
const parsed_gpu_name = try allocator.alloc(u8, size);
|
||||||
|
_ = std.mem.replace(u8, name, "Intel Corporation", "Intel", parsed_gpu_name);
|
||||||
|
|
||||||
|
return parsed_gpu_name;
|
||||||
|
} else if (std.mem.startsWith(u8, name, "NVIDIA Corporation")) {
|
||||||
|
const size = std.mem.replacementSize(u8, name, "NVIDIA Corporation", "NVIDIA");
|
||||||
|
const parsed_gpu_name = try allocator.alloc(u8, size);
|
||||||
|
_ = std.mem.replace(u8, name, "NVIDIA Corporation", "NVIDIA", parsed_gpu_name);
|
||||||
|
|
||||||
|
return parsed_gpu_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getRamInfo(allocator: std.mem.Allocator) !RamInfo {
|
pub fn getRamInfo(allocator: std.mem.Allocator) !RamInfo {
|
||||||
// Reads /proc/meminfo
|
// Reads /proc/meminfo
|
||||||
const meminfo_path = "/proc/meminfo";
|
const meminfo_path = "/proc/meminfo";
|
||||||
@@ -260,7 +327,7 @@ pub fn getDiskSize(disk_path: []const u8) !DiskInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const total_size = stat.f_blocks * stat.f_frsize;
|
const total_size = stat.f_blocks * stat.f_frsize;
|
||||||
const free_size = stat.f_bavail * stat.f_frsize;
|
const free_size = stat.f_bfree * stat.f_frsize;
|
||||||
const used_size = total_size - free_size;
|
const used_size = total_size - free_size;
|
||||||
|
|
||||||
const used_size_percentage = (used_size * 100) / total_size;
|
const used_size_percentage = (used_size * 100) / total_size;
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
||||||
const term_progrm = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||||
return allocator.dupe(u8, "Unknown");
|
return allocator.dupe(u8, "Unknown");
|
||||||
} else return err;
|
} else return err;
|
||||||
return term_progrm;
|
return term_program;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ pub fn getDiskSize(disk_path: []const u8) !DiskInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const total_size = stat.f_blocks * stat.f_frsize;
|
const total_size = stat.f_blocks * stat.f_frsize;
|
||||||
const free_size = stat.f_bavail * stat.f_frsize;
|
const free_size = stat.f_bfree * stat.f_frsize;
|
||||||
const used_size = total_size - free_size;
|
const used_size = total_size - free_size;
|
||||||
|
|
||||||
const used_size_percentage = (used_size * 100) / total_size;
|
const used_size_percentage = (used_size * 100) / total_size;
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ pub fn getShell(allocator: std.mem.Allocator) ![]u8 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
pub fn getTerminalName(allocator: std.mem.Allocator) ![]u8 {
|
||||||
const term_progrm = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
const term_program = std.process.getEnvVarOwned(allocator, "TERM_PROGRAM") catch |err| if (err == error.EnvironmentVariableNotFound) {
|
||||||
return allocator.dupe(u8, "Unknown");
|
return allocator.dupe(u8, "Unknown");
|
||||||
} else return err;
|
} else return err;
|
||||||
return term_progrm;
|
return term_program;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user