From ca8a810d5738ecd3d436afecdec2a5999e86376b Mon Sep 17 00:00:00 2001 From: nicknase27 Date: Thu, 8 Oct 2026 09:18:40 +0200 Subject: [PATCH] add mac support? --- src/main.rs | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8b38c35..6112312 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use std::env; use std::fs::read_to_string; +use std::process::Command; fn print_logo() { print!( @@ -35,9 +36,15 @@ fn get_os() -> String { return String::new(); } -#[cfg(target_os = "unix")] +#[cfg(target_os = "macos")] fn get_os() -> String { - return String::new(); + let output = Command::new("sw_vers").arg("-productVersion").output().ok(); + if let Some(out) = output { + let version = String::from_utf8_lossy(&out.stdout).trim().to_string(); + format!("macOS {}", version) + } else { + "macOS".to_string() + } } #[cfg(unix)] @@ -48,11 +55,22 @@ fn get_shell() -> String { } } -#[cfg(unix)] + +#[cfg(target_os = "linux")] fn get_host() -> String { read_to_string("/etc/hostname").unwrap().trim().to_string() } +#[cfg(target_os = "macos")] +fn get_host() -> String { + let output = Command::new("hostname").output().ok(); + if let Some(out) = output { + String::from_utf8_lossy(&out.stdout).trim().to_string() + } else { + String::new() + } +} + #[cfg(target_os = "linux")] fn get_kernel() -> String { let kernel = read_to_string("/proc/sys/kernel/osrelease") @@ -62,9 +80,15 @@ fn get_kernel() -> String { format!("Linux {}", kernel) } -#[cfg(not(target_os = "linux"))] +#[cfg(target_os = "macos")] fn get_kernel() -> String { - String::new() + let output = Command::new("uname").arg("-r").output().ok(); + if let Some(out) = output { + let version = String::from_utf8_lossy(&out.stdout).trim().to_string(); + format!("Darwin {}", version) + } else { + "Darwin".to_string() + } } fn get_terminal() -> String { @@ -110,10 +134,8 @@ fn get_memory() -> String { } } -#[cfg(not(target_os = "linux"))] -fn get_memory() -> String { - String::new() -} +#[cfg(target_os = "macos")] +fn get_memory() -> String { String::new() } fn main() { let os = get_os();