refactor: rename detection import

This commit is contained in:
utox39
2025-03-18 11:02:46 +01:00
parent 0dfc050fbe
commit e32eb85e94

View File

@@ -1,5 +1,5 @@
const std = @import("std"); const std = @import("std");
const os_module = @import("detection.zig").os_module; const detection = @import("detection.zig").os_module;
pub fn main() !void { pub fn main() !void {
const stdout_file = std.io.getStdOut().writer(); const stdout_file = std.io.getStdOut().writer();
@@ -9,56 +9,56 @@ pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator(); const allocator = gpa.allocator();
const kernel_info = try os_module.getKernelInfo(allocator); const kernel_info = try detection.getKernelInfo(allocator);
try stdout.print("Kernel: {s} {s}\n", .{ kernel_info.kernel_name, kernel_info.kernel_release }); try stdout.print("Kernel: {s} {s}\n", .{ kernel_info.kernel_name, kernel_info.kernel_release });
try bw.flush(); try bw.flush();
allocator.free(kernel_info.kernel_name); allocator.free(kernel_info.kernel_name);
allocator.free(kernel_info.kernel_release); allocator.free(kernel_info.kernel_release);
const os_info = try os_module.getOsInfo(allocator); const os_info = try detection.getOsInfo(allocator);
try stdout.print("OS: {s}\n", .{os_info}); try stdout.print("OS: {s}\n", .{os_info});
try bw.flush(); try bw.flush();
allocator.free(os_info); allocator.free(os_info);
const username = try os_module.getUsername(allocator); const username = try detection.getUsername(allocator);
try stdout.print("User: {s}\n", .{username}); try stdout.print("User: {s}\n", .{username});
try bw.flush(); try bw.flush();
allocator.free(username); allocator.free(username);
const hostname = try os_module.getHostname(allocator); const hostname = try detection.getHostname(allocator);
try stdout.print("Hostname: {s}\n", .{hostname}); try stdout.print("Hostname: {s}\n", .{hostname});
try bw.flush(); try bw.flush();
allocator.free(hostname); allocator.free(hostname);
const locale = try os_module.getLocale(allocator); const locale = try detection.getLocale(allocator);
try stdout.print("Locale: {s}\n", .{locale}); try stdout.print("Locale: {s}\n", .{locale});
try bw.flush(); try bw.flush();
allocator.free(locale); allocator.free(locale);
const uptime = try os_module.getSystemUptime(); const uptime = try detection.getSystemUptime();
try stdout.print("Uptime: {} days, {} hours, {} minutes\n", .{ uptime.days, uptime.hours, uptime.minutes }); try stdout.print("Uptime: {} days, {} hours, {} minutes\n", .{ uptime.days, uptime.hours, uptime.minutes });
try bw.flush(); try bw.flush();
const shell = try os_module.getShell(allocator); const shell = try detection.getShell(allocator);
try stdout.print("Shell: {s}", .{shell}); try stdout.print("Shell: {s}", .{shell});
try bw.flush(); try bw.flush();
allocator.free(shell); allocator.free(shell);
const cpu_info = try os_module.getCpuInfo(allocator); const cpu_info = try detection.getCpuInfo(allocator);
try stdout.print("cpu: {s} ({})\n", .{ cpu_info.cpu_name, cpu_info.cpu_cores }); try stdout.print("cpu: {s} ({})\n", .{ cpu_info.cpu_name, cpu_info.cpu_cores });
try bw.flush(); try bw.flush();
allocator.free(cpu_info.cpu_name); allocator.free(cpu_info.cpu_name);
const gpu_info = try os_module.getGpuInfo(allocator); const gpu_info = try detection.getGpuInfo(allocator);
try stdout.print("gpu: {s} ({})\n", .{ gpu_info.gpu_name, gpu_info.gpu_cores }); try stdout.print("gpu: {s} ({})\n", .{ gpu_info.gpu_name, gpu_info.gpu_cores });
try bw.flush(); try bw.flush();
allocator.free(gpu_info.gpu_name); allocator.free(gpu_info.gpu_name);
const ram_info = try os_module.getRamInfo(); const ram_info = try detection.getRamInfo();
try stdout.print("ram: {d:.2} / {d:.2} GB ({}%)\n", .{ ram_info.ram_usage, ram_info.ram_size, ram_info.ram_usage_percentage }); try stdout.print("ram: {d:.2} / {d:.2} GB ({}%)\n", .{ ram_info.ram_usage, ram_info.ram_size, ram_info.ram_usage_percentage });
try bw.flush(); try bw.flush();
const swap_info = try os_module.getSwapInfo(); const swap_info = try detection.getSwapInfo();
if (swap_info) |s| { if (swap_info) |s| {
try stdout.print("Swap: {d:.2} / {d:.2} GB ({}%)\n", .{ s.swap_usage, s.swap_size, s.swap_usage_percentage }); try stdout.print("Swap: {d:.2} / {d:.2} GB ({}%)\n", .{ s.swap_usage, s.swap_size, s.swap_usage_percentage });
} else { } else {
@@ -66,16 +66,16 @@ pub fn main() !void {
} }
try bw.flush(); try bw.flush();
const diskInfo = try os_module.getDiskSize("/"); const diskInfo = try detection.getDiskSize("/");
try stdout.print("disk ({s}): {d:.2} / {d:.2} GB ({}%)\n", .{ diskInfo.disk_path, diskInfo.disk_usage, diskInfo.disk_size, diskInfo.disk_usage_percentage }); try stdout.print("disk ({s}): {d:.2} / {d:.2} GB ({}%)\n", .{ diskInfo.disk_path, diskInfo.disk_usage, diskInfo.disk_size, diskInfo.disk_usage_percentage });
try bw.flush(); try bw.flush();
const terminal_name = try os_module.getTerminalName(allocator); const terminal_name = try detection.getTerminalName(allocator);
try stdout.print("terminal: {s}\n", .{terminal_name}); try stdout.print("terminal: {s}\n", .{terminal_name});
try bw.flush(); try bw.flush();
allocator.free(terminal_name); allocator.free(terminal_name);
const net_info_list = try os_module.getNetInfo(allocator); const net_info_list = try detection.getNetInfo(allocator);
for (net_info_list.items) |n| { for (net_info_list.items) |n| {
try stdout.print("Local IP ({s}): {s}\n", .{ n.interface_name, n.ipv4_addr }); try stdout.print("Local IP ({s}): {s}\n", .{ n.interface_name, n.ipv4_addr });
try bw.flush(); try bw.flush();