This commit is contained in:
neoarz
2026-01-05 17:57:53 -05:00
commit 136b77644c
9 changed files with 1116 additions and 0 deletions

32
src/helpers/display.rs Normal file
View File

@@ -0,0 +1,32 @@
use display_info::DisplayInfo;
pub fn get_display_info() -> String {
let displays = DisplayInfo::all().unwrap_or_else(|_| vec![]);
if let Some(main) = displays.iter().find(|d| d.is_primary) {
let p_width = (main.width as f32 * main.scale_factor) as u32;
let p_height = (main.height as f32 * main.scale_factor) as u32;
let diag_mm = ((main.width_mm as f32).powi(2) + (main.height_mm as f32).powi(2)).sqrt();
let inches = (diag_mm / 25.4).round() as u32;
let name = if main.name.is_empty() {
"Color LCD"
} else {
&main.name
};
let tag = if main.is_primary {
"[Built-in]"
} else {
"[External]"
};
format!(
"Display ({}): {}x{} @ {}x in {}\", {} Hz {}",
name, p_width, p_height, main.scale_factor as u32, inches, main.frequency as u32, tag
)
} else {
"unknown".to_string()
}
}

4
src/helpers/mod.rs Normal file
View File

@@ -0,0 +1,4 @@
pub mod display;
pub mod packages;
pub mod shell;
pub mod uptime;

19
src/helpers/packages.rs Normal file
View File

@@ -0,0 +1,19 @@
use std::process::Command;
pub fn get_brew_info() -> String {
let brew_count = count_lines("--formula");
let cask_count = count_lines("--cask");
format!("{} (brew), {} (brew-cask)", brew_count, cask_count)
}
fn count_lines(arg: &str) -> usize {
let output = Command::new("brew").arg("list").arg(arg).output();
match output {
Ok(out) => {
let stdout = String::from_utf8_lossy(&out.stdout);
stdout.lines().filter(|l| !l.is_empty()).count()
}
Err(_) => 0,
}
}

22
src/helpers/shell.rs Normal file
View File

@@ -0,0 +1,22 @@
use std::env;
use std::process::Command;
pub fn get_shell_info() -> String {
let shell_path = env::var("SHELL").unwrap_or_else(|_| "unknown".to_string());
let shell_name = shell_path.split('/').last().unwrap_or("unknown");
let version = Command::new(&shell_path)
.arg("--version")
.output()
.map(|output| {
let stdout = String::from_utf8_lossy(&output.stdout);
// Most shells return "zsh 5.9 (x86_64-apple-darwin24.0)" or similar; we just want the first two words
stdout
.split_whitespace()
.take(2)
.collect::<Vec<_>>()
.join(" ")
})
.unwrap_or_else(|_| shell_name.to_string());
version
}

11
src/helpers/uptime.rs Normal file
View File

@@ -0,0 +1,11 @@
pub fn get_uptime(seconds: u64) -> String {
let days = seconds / 86400;
let hours = (seconds % 86400) / 3600;
let minutes = (seconds % 3600) / 60;
if days > 0 {
format!("{} days, {} hours, {} minutes", days, hours, minutes)
} else {
format!("{} hours, {} minutes", hours, minutes)
}
}