add mac support?

This commit is contained in:
nicknase27 committed 2026-10-08 09:18:40 +02:00
1 parent eb5f708699
commit ca8a810d57
1 file changed
+31 -9
+31 -9
View File
@@ -1,5 +1,6 @@
use std::env; use std::env;
use std::fs::read_to_string; use std::fs::read_to_string;
use std::process::Command;
fn print_logo() { fn print_logo() {
print!( print!(
@@ -35,9 +36,15 @@ fn get_os() -> String {
return String::new(); return String::new();
} }
#[cfg(target_os = "unix")] #[cfg(target_os = "macos")]
fn get_os() -> String { 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)] #[cfg(unix)]
@@ -48,11 +55,22 @@ fn get_shell() -> String {
} }
} }
#[cfg(unix)]
#[cfg(target_os = "linux")]
fn get_host() -> String { fn get_host() -> String {
read_to_string("/etc/hostname").unwrap().trim().to_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")] #[cfg(target_os = "linux")]
fn get_kernel() -> String { fn get_kernel() -> String {
let kernel = read_to_string("/proc/sys/kernel/osrelease") let kernel = read_to_string("/proc/sys/kernel/osrelease")
@@ -62,9 +80,15 @@ fn get_kernel() -> String {
format!("Linux {}", kernel) format!("Linux {}", kernel)
} }
#[cfg(not(target_os = "linux"))] #[cfg(target_os = "macos")]
fn get_kernel() -> String { 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 { fn get_terminal() -> String {
@@ -110,10 +134,8 @@ fn get_memory() -> String {
} }
} }
#[cfg(not(target_os = "linux"))] #[cfg(target_os = "macos")]
fn get_memory() -> String { fn get_memory() -> String { String::new() }
String::new()
}
fn main() { fn main() {
let os = get_os(); let os = get_os();