feat: add distro, kernel version, and display resolution+Hz to system info
Distro parsed from /etc/os-release PRETTY_NAME. Kernel from uname -r. Display resolution and refresh rate from xrandr (linux only, N/A elsewhere).
This commit is contained in:
+78
-2
@@ -1,14 +1,18 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
use crate::config::{GameConfig, VsyncMode};
|
use crate::config::{GameConfig, VsyncMode};
|
||||||
use crate::constants::SEED;
|
use crate::constants::SEED;
|
||||||
|
|
||||||
pub fn print_system_info(config: &GameConfig) {
|
pub fn print_system_info(config: &GameConfig) {
|
||||||
let os = format!("{} {}", env::consts::OS, env::consts::ARCH);
|
let os = format!("{} {}", env::consts::OS, env::consts::ARCH);
|
||||||
|
let distro = distro_info();
|
||||||
|
let kernel = kernel_info();
|
||||||
let cpu = cpu_info();
|
let cpu = cpu_info();
|
||||||
let gpu = gpu_info();
|
let gpu = gpu_info();
|
||||||
let (ram_total, ram_free) = mem_info();
|
let (ram_total, ram_free) = mem_info();
|
||||||
|
let (res, hz) = display_info();
|
||||||
let display = vsync_label(&config.display.vsync);
|
let display = vsync_label(&config.display.vsync);
|
||||||
let radius = config.initial_chunk_radius;
|
let radius = config.initial_chunk_radius;
|
||||||
let seed = SEED;
|
let seed = SEED;
|
||||||
@@ -21,6 +25,8 @@ pub fn print_system_info(config: &GameConfig) {
|
|||||||
println!("║{:^width$}║", "DORF SYSTEM", width = line_width + 2);
|
println!("║{:^width$}║", "DORF SYSTEM", width = line_width + 2);
|
||||||
println!("╠═{hline}═╣");
|
println!("╠═{hline}═╣");
|
||||||
println!("║ OS: {:<width$}║", os, width = line_width);
|
println!("║ OS: {:<width$}║", os, width = line_width);
|
||||||
|
println!("║ Distro: {:<width$}║", distro, width = line_width);
|
||||||
|
println!("║ Kernel: {:<width$}║", kernel, width = line_width);
|
||||||
println!("║ CPU: {:<width$}║", cpu, width = line_width);
|
println!("║ CPU: {:<width$}║", cpu, width = line_width);
|
||||||
println!("║ GPU: {:<width$}║", gpu, width = line_width);
|
println!("║ GPU: {:<width$}║", gpu, width = line_width);
|
||||||
println!(
|
println!(
|
||||||
@@ -28,7 +34,11 @@ pub fn print_system_info(config: &GameConfig) {
|
|||||||
format!("{} GB ({} GB free)", ram_total, ram_free),
|
format!("{} GB ({} GB free)", ram_total, ram_free),
|
||||||
width = line_width
|
width = line_width
|
||||||
);
|
);
|
||||||
println!("║ Display: {:<width$}║", display, width = line_width);
|
println!(
|
||||||
|
"║ Display: {:<width$}║",
|
||||||
|
format!("{} @ {}Hz {}", res, hz, display),
|
||||||
|
width = line_width
|
||||||
|
);
|
||||||
println!(
|
println!(
|
||||||
"║ Radius: {:<width$}║",
|
"║ Radius: {:<width$}║",
|
||||||
format!("{} chunks", radius),
|
format!("{} chunks", radius),
|
||||||
@@ -112,7 +122,73 @@ fn mem_info() -> (u64, u64) {
|
|||||||
fn vsync_label(mode: &VsyncMode) -> &'static str {
|
fn vsync_label(mode: &VsyncMode) -> &'static str {
|
||||||
match mode {
|
match mode {
|
||||||
VsyncMode::Vsync => "vsync",
|
VsyncMode::Vsync => "vsync",
|
||||||
VsyncMode::Mailbox => "mailbox vsync",
|
VsyncMode::Mailbox => "mailbox",
|
||||||
VsyncMode::Uncapped => "uncapped",
|
VsyncMode::Uncapped => "uncapped",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn distro_info() -> String {
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
if let Ok(content) = fs::read_to_string("/etc/os-release") {
|
||||||
|
let pretty_name = content
|
||||||
|
.lines()
|
||||||
|
.find(|l| l.starts_with("PRETTY_NAME="))
|
||||||
|
.and_then(|l| l.split('=').nth(1))
|
||||||
|
.map(|s| s.trim_matches('"').to_string());
|
||||||
|
if let Some(name) = pretty_name {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String::from("Unknown distro")
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
{
|
||||||
|
String::from("N/A")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn kernel_info() -> String {
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
if let Ok(output) = Command::new("uname").arg("-r").output() {
|
||||||
|
if let Ok(kernel) = String::from_utf8(output.stdout) {
|
||||||
|
return kernel.trim().to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String::from("Unknown kernel")
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
{
|
||||||
|
String::from("N/A")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_info() -> (String, String) {
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
if let Ok(output) = Command::new("xrandr").output() {
|
||||||
|
if let Ok(xr) = String::from_utf8(output.stdout) {
|
||||||
|
let lines: Vec<&str> = xr.lines().collect();
|
||||||
|
if let Some(current) = lines.iter().find(|l| l.contains("+*")) {
|
||||||
|
let parts: Vec<&str> = current.split_whitespace().collect();
|
||||||
|
let res = parts.get(0).unwrap_or(&"unknown");
|
||||||
|
let mut hz = String::from("60");
|
||||||
|
for part in &parts[1..] {
|
||||||
|
if part.ends_with("Hz") || part.parse::<f32>().is_ok() {
|
||||||
|
hz = part
|
||||||
|
.trim_end_matches("Hz*")
|
||||||
|
.trim_end_matches("Hz")
|
||||||
|
.to_string();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (res.to_string(), hz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
return (String::from("N/A"), String::from("N/A"));
|
||||||
|
(String::from("unknown"), String::from("?"))
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user