Added tests and tentative support for GPU recognition on Windows
This commit is contained in:
parent
eefb431ae7
commit
ab33a365f9
50
Cargo.lock
generated
50
Cargo.lock
generated
@ -223,6 +223,12 @@ dependencies = [
|
||||
"cxx-build",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
version = "0.3.60"
|
||||
@ -322,7 +328,8 @@ dependencies = [
|
||||
"chrono",
|
||||
"colored",
|
||||
"quoted-string",
|
||||
"sys-info",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"sysinfo",
|
||||
"time 0.3.17",
|
||||
"whoami",
|
||||
@ -374,6 +381,12 @@ dependencies = [
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde"
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
@ -391,6 +404,31 @@ name = "serde"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.152"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.91"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "877c235533714907a8c2464236f5c4b2a17262ef1bd71f38f35ea592c8da6883"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
@ -403,16 +441,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sys-info"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b3a0d0aba8bf96a0e1ddfdc352fc53b3df7f39318c71854910c3c4b024ae52c"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sysinfo"
|
||||
version = "0.27.2"
|
||||
|
@ -9,8 +9,11 @@ edition = "2021"
|
||||
chrono = "0.4.23"
|
||||
colored = "2.0.0"
|
||||
quoted-string = "0.6.1"
|
||||
sys-info = "0.9.1"
|
||||
sysinfo = "0.27.2"
|
||||
time = "0.3.17"
|
||||
#users = "0.11.0"
|
||||
whoami = "1.3.0"
|
||||
serde_json = "1.0.91"
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1.0.152"
|
||||
features = ["std", "derive", "serde_derive"]
|
||||
|
47
src/main.rs
47
src/main.rs
@ -1,3 +1,4 @@
|
||||
|
||||
use chrono::*;
|
||||
use colored::*;
|
||||
use sysinfo::*;
|
||||
@ -22,6 +23,7 @@ fn main() {
|
||||
color_print("Uptime:\t", '', &format!("{}s", sys_info.uptime), "bright black");
|
||||
color_print("Shell:\t", '', &sys_info.shell, "bright magenta");
|
||||
color_print("CPU:\t", '', &sys_info.cpu, "green");
|
||||
|
||||
}
|
||||
|
||||
fn color_print(field_title: &str, icon: char, field: &str, color: &str) {
|
||||
@ -32,6 +34,7 @@ fn color_print(field_title: &str, icon: char, field: &str, color: &str) {
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InformationStruct {
|
||||
username: String,
|
||||
hostname: String,
|
||||
@ -82,7 +85,12 @@ impl InformationStruct {
|
||||
|
||||
cpu: String::from(sys.cpus()[0].brand()),
|
||||
|
||||
_gpu: String::from("Unknown GPU"), // TODO: Add GPU detection.
|
||||
_gpu: {
|
||||
if sys.name().unwrap_or(String::from("Unknown System")) == "Windows" {
|
||||
println!("{:#?}", std::process::Command::new("wmic").arg("path").arg("win32_VideoController").arg("get").arg("name").output().expect("Unknown GPU"));
|
||||
}
|
||||
String::from("Unknown GPU")
|
||||
}, // TODO: Add GPU detection.
|
||||
|
||||
_memory: String::from("Unknown memory"), // TODO: Add memory detection.
|
||||
|
||||
@ -113,7 +121,14 @@ impl InformationStruct {
|
||||
"macOS" => '',
|
||||
"Unknown System" => '?',
|
||||
_ => {
|
||||
unreachable!()
|
||||
if sys
|
||||
.name()
|
||||
.unwrap_or(String::from("Unknown System"))
|
||||
.contains("linux") {
|
||||
''
|
||||
} else {
|
||||
'?'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@ -126,13 +141,37 @@ impl InformationStruct {
|
||||
"FreeBSD" => String::from("red"),
|
||||
"Ubuntu Linux" => String::from("orange"),
|
||||
"Arch Linux" | "Windows" | "PopOS" => String::from("bright cyan"),
|
||||
"Fedora Linux" | "Kali Linux" => String::from("bright blue"),
|
||||
"Fedora Linux" | "Kali Linux" | "Alpine Linux" => String::from("bright blue"),
|
||||
"OpenSUSE" | "Linux Mint" | "Android" => String::from("bright green"),
|
||||
"EndeavourOS" | "Gentoo linux" => String::from("purple"),
|
||||
"EndeavourOS" | "Gentoo linux" | "CentOS" => String::from("purple"),
|
||||
"iOS" | "macOS" | "ElementaryOS" => String::from("bright white"),
|
||||
"Alma Linux" => String::from("yellow"),
|
||||
|
||||
_ => String::from("bright white"),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use crate::InformationStruct;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
pub fn log_gathered_data() {
|
||||
let sys_info = InformationStruct::new();
|
||||
let data_string = format!("{:#?}", sys_info);
|
||||
let result = fs::write("./test_output.txt", data_string);
|
||||
|
||||
if result.is_ok() {
|
||||
println!("\nHEY THERE! A logging file was generated by this test. \nIt's located in this folder, and called 'test_output.txt'. \nSEND THIS FILE to the maintainer of the project!\n");
|
||||
} else {
|
||||
println!("Woops. A file wasn't able to be generated. The program or user might not have permission to make files in this directory.");
|
||||
};
|
||||
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
}
|
15
test_output.txt
Normal file
15
test_output.txt
Normal file
@ -0,0 +1,15 @@
|
||||
InformationStruct {
|
||||
username: "river",
|
||||
hostname: "desktop-s5lkjhl",
|
||||
os_name: "Arch Linux",
|
||||
os_ver: "Unknown System Version",
|
||||
kernel_ver: "5.15.79.1-microsoft-standard-WSL2",
|
||||
uptime: 39416,
|
||||
shell: "zsh",
|
||||
_terminal: "Unknown Terminal",
|
||||
cpu: "Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz",
|
||||
_gpu: "Unknown GPU",
|
||||
_memory: "Unknown memory",
|
||||
icon: '\u{f303}',
|
||||
color: "bright cyan",
|
||||
}
|
Loading…
Reference in New Issue
Block a user