You've already forked neo64fetch
mirror of
https://github.com/neoarz/neo64fetch.git
synced 2026-02-09 06:43:26 +01:00
init
This commit is contained in:
32
src/helpers/display.rs
Normal file
32
src/helpers/display.rs
Normal 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
4
src/helpers/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod display;
|
||||
pub mod packages;
|
||||
pub mod shell;
|
||||
pub mod uptime;
|
||||
19
src/helpers/packages.rs
Normal file
19
src/helpers/packages.rs
Normal 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
22
src/helpers/shell.rs
Normal 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
11
src/helpers/uptime.rs
Normal 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)
|
||||
}
|
||||
}
|
||||
59
src/main.rs
Normal file
59
src/main.rs
Normal file
@@ -0,0 +1,59 @@
|
||||
// neoarz
|
||||
// neo64fetch - "jarvis, rewrite this project in rust"
|
||||
|
||||
// use colored::*;
|
||||
use display_info::DisplayInfo;
|
||||
use std::env;
|
||||
use sysinfo::System;
|
||||
mod helpers;
|
||||
|
||||
struct Stats {
|
||||
// Neoarz[at]Mac
|
||||
username: String,
|
||||
hostname: String,
|
||||
// --------------
|
||||
os: String,
|
||||
host: String,
|
||||
kernel: String,
|
||||
uptime: String,
|
||||
packages: String,
|
||||
shell: String,
|
||||
display: String,
|
||||
|
||||
// Extra fields which are usually appended
|
||||
architecture: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_all();
|
||||
|
||||
let stats = Stats {
|
||||
hostname: System::host_name().unwrap_or_else(|| "<unknown>".to_owned()),
|
||||
username: env::var("USER")
|
||||
.or_else(|_| env::var("USERNAME"))
|
||||
.unwrap_or_else(|_| "<unknown>".to_owned()),
|
||||
os: System::long_os_version().unwrap_or_else(|| "<unknown>".to_owned()),
|
||||
host: System::name().unwrap_or_else(|| "<unknown>".to_owned()),
|
||||
architecture: System::cpu_arch(),
|
||||
kernel: System::kernel_long_version(),
|
||||
uptime: helpers::uptime::get_uptime(System::uptime()),
|
||||
packages: helpers::packages::get_brew_info(),
|
||||
shell: helpers::shell::get_shell_info(),
|
||||
display: helpers::display::get_display_info(),
|
||||
};
|
||||
|
||||
// Testing each component separately; going to comment out at the end
|
||||
{
|
||||
println!("{}", stats.username);
|
||||
println!("{}", stats.hostname);
|
||||
println!("{}", stats.os);
|
||||
println!("{}", stats.host);
|
||||
println!("{}", stats.architecture);
|
||||
println!("{}", stats.kernel);
|
||||
println!("{}", stats.uptime);
|
||||
println!("{}", stats.packages);
|
||||
println!("{}", stats.shell);
|
||||
println!("{}", stats.display);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user