diff --git a/build.zig.zon b/build.zig.zon index 2a78f4d..d82f054 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -10,7 +10,7 @@ // This is a [Semantic Version](https://semver.org/). // In a future version of Zig it will be used for package deduplication. - .version = "0.6.2", + .version = "0.7.0", // Together with name, this represents a globally unique package // identifier. This field is generated by the Zig toolchain when the diff --git a/src/linux/hardware.zig b/src/linux/hardware.zig index dc44579..d94b4ae 100644 --- a/src/linux/hardware.zig +++ b/src/linux/hardware.zig @@ -114,8 +114,13 @@ pub fn getGpuInfo(allocator: std.mem.Allocator) !std.ArrayList(GpuInfo) { devices.*.device_id, ); + const gpu_name = try allocator.dupe(u8, std.mem.span(name)); + defer allocator.free(gpu_name); + + const parsed_gpu_name = try parseGpuName(allocator, gpu_name); + 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_freq = 0.0, }); @@ -133,6 +138,32 @@ pub fn getGpuInfo(allocator: std.mem.Allocator) !std.ArrayList(GpuInfo) { 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 name; +} + pub fn getRamInfo(allocator: std.mem.Allocator) !RamInfo { // Reads /proc/meminfo const meminfo_path = "/proc/meminfo"; diff --git a/src/linux/user.zig b/src/linux/user.zig index 906ffcb..d6bb3eb 100644 --- a/src/linux/user.zig +++ b/src/linux/user.zig @@ -24,8 +24,8 @@ pub fn getShell(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"); } else return err; - return term_progrm; + return term_program; } diff --git a/src/macos/user.zig b/src/macos/user.zig index 34abd0f..52da9fb 100644 --- a/src/macos/user.zig +++ b/src/macos/user.zig @@ -27,8 +27,8 @@ pub fn getShell(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"); } else return err; - return term_progrm; + return term_program; }