major refactor. this is gonna suck.
This commit is contained in:
parent
e77e611e2d
commit
ddb3c9b291
132
Cargo.lock
generated
132
Cargo.lock
generated
@ -17,7 +17,7 @@ version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"hermit-abi 0.1.19",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
@ -88,6 +88,49 @@ version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-channel"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"cfg-if",
|
||||
"crossbeam-utils",
|
||||
"memoffset",
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.85"
|
||||
@ -132,6 +175,12 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.19"
|
||||
@ -141,6 +190,15 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "iana-time-zone"
|
||||
version = "0.1.53"
|
||||
@ -204,6 +262,24 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memoffset"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc51db7b362b205941f71232e56c625156eb9a929f8cf74a428fd5bc094a4afc"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.45"
|
||||
@ -223,6 +299,16 @@ dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b"
|
||||
dependencies = [
|
||||
"hermit-abi 0.2.6",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.17.0"
|
||||
@ -237,6 +323,7 @@ dependencies = [
|
||||
"colored",
|
||||
"quoted-string",
|
||||
"sys-info",
|
||||
"sysinfo",
|
||||
"time 0.3.17",
|
||||
"whoami",
|
||||
]
|
||||
@ -265,6 +352,34 @@ version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a206a30ce37189d1340e7da2ee0b4d65e342590af676541c23a4f3959ba272e"
|
||||
|
||||
[[package]]
|
||||
name = "rayon"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7"
|
||||
dependencies = [
|
||||
"either",
|
||||
"rayon-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rayon-core"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3"
|
||||
dependencies = [
|
||||
"crossbeam-channel",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-utils",
|
||||
"num_cpus",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "scopeguard"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
|
||||
|
||||
[[package]]
|
||||
name = "scratch"
|
||||
version = "1.0.3"
|
||||
@ -298,6 +413,21 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sysinfo"
|
||||
version = "0.27.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17351d0e9eb8841897b14e9669378f3c69fb57779cc04f8ca9a9d512edfb2563"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"core-foundation-sys",
|
||||
"libc",
|
||||
"ntapi",
|
||||
"once_cell",
|
||||
"rayon",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.3"
|
||||
|
@ -10,6 +10,7 @@ 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"
|
129
src/main.rs
129
src/main.rs
@ -1,96 +1,45 @@
|
||||
use colored::*;
|
||||
use sys_info::*;
|
||||
use sysinfo::*;
|
||||
use whoami::*;
|
||||
use chrono::*;
|
||||
|
||||
fn get_os() -> OsInfo {
|
||||
let current_info: OsInfo = match os_type() {
|
||||
Ok(os_type) => match os_type.as_ref() {
|
||||
"Windows" => OsInfo {
|
||||
name: String::from("Windows"),
|
||||
icon: '',
|
||||
term_color: String::from("bright cyan"),
|
||||
},
|
||||
"Darwin" => OsInfo {
|
||||
name: String::from("Apple Darwin"),
|
||||
icon: '',
|
||||
term_color: String::from("bright white"),
|
||||
},
|
||||
"Linux" => get_linux_info(),
|
||||
_ => OsInfo {
|
||||
name: String::from("Unknown"),
|
||||
icon: '',
|
||||
term_color: String::from("bright white"),
|
||||
},
|
||||
},
|
||||
_ => OsInfo {
|
||||
name: String::from("Unknown"),
|
||||
icon: '',
|
||||
term_color: String::from("bright white"),
|
||||
},
|
||||
};
|
||||
|
||||
current_info
|
||||
}
|
||||
|
||||
fn get_linux_info() -> OsInfo {
|
||||
match linux_os_release() {
|
||||
Ok(release_info) => match release_info.pretty_name.unwrap().as_ref() {
|
||||
"Arch Linux" => OsInfo {
|
||||
name: String::from("Arch Linux"),
|
||||
icon: '',
|
||||
term_color: String::from("bright cyan"),
|
||||
},
|
||||
"Linux Debian" => OsInfo {
|
||||
name: String::from("Linux Debian"),
|
||||
icon: '',
|
||||
term_color: String::from("red"),
|
||||
},
|
||||
"Fedora Linux" => OsInfo {
|
||||
name: String::from("Fedora Linux"),
|
||||
icon: '',
|
||||
term_color: String::from("bright blue"),
|
||||
},
|
||||
_ => OsInfo {
|
||||
name: String::from("Unknown Linux"),
|
||||
icon: '',
|
||||
term_color: String::from("bright white"),
|
||||
},
|
||||
},
|
||||
_ => OsInfo {
|
||||
name: String::from("Unknown Linux"),
|
||||
icon: '',
|
||||
term_color: String::from("bright white"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
struct OsInfo {
|
||||
name: String,
|
||||
icon: char,
|
||||
term_color: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
println!();
|
||||
|
||||
let date = chrono::Utc::now();
|
||||
let date_string = format!("{}, {}-{}-{} at {}:{}", date.weekday(), date.year(), date.month(), date.day(), date.hour(), date.minute());
|
||||
println!("{} {}", format!("Date:").bright_white(), format!(" {}", date_string).bright_yellow());
|
||||
|
||||
let current_info = get_os();
|
||||
let info_string = format!("{} {}", current_info.icon, current_info.name).color(current_info.term_color).bold();
|
||||
|
||||
println!("{} {}", String::from("Host:").bright_white(), format!(" {}@{}", username(), whoami::hostname()).bold());
|
||||
|
||||
println!("{} {}", String::from("OS:").bright_white(), info_string);
|
||||
if proc_total().is_ok() {
|
||||
println!("{} {}", String::from("Procs:").bright_white(), format!(" {}", proc_total().unwrap()).magenta().bold());
|
||||
}
|
||||
|
||||
if cpu_num().is_ok() & cpu_speed().is_ok() {
|
||||
println!("{} {}", String::from("CPUs:").bright_white(), format!(" {} @ {}mhz", cpu_num().unwrap(), cpu_speed().unwrap()).bright_black().bold())
|
||||
}
|
||||
|
||||
let sys_info = InformationStruct::new();
|
||||
println!("{}", sys_info.os_name);
|
||||
}
|
||||
|
||||
struct InformationStruct {
|
||||
username: String,
|
||||
hostname: String,
|
||||
os_name: String,
|
||||
os_ver: String,
|
||||
kernel_ver: String,
|
||||
uptime: u64,
|
||||
shell: String,
|
||||
terminal: String,
|
||||
cpu: String,
|
||||
gpu: String,
|
||||
memory: String,
|
||||
icon: char,
|
||||
}
|
||||
|
||||
impl InformationStruct {
|
||||
fn new() -> Self {
|
||||
let mut sys = System::new_all();
|
||||
sys.refresh_all();
|
||||
Self{
|
||||
username: whoami::username(),
|
||||
hostname: whoami::hostname(),
|
||||
os_name: sys.name().unwrap_or(String::from("Unknown System")),
|
||||
os_ver: sys.os_version().unwrap_or(String::from("Unknown System Version")),
|
||||
kernel_ver: sys.kernel_version().unwrap_or(String::from("Unknown Kernel Version")),
|
||||
uptime: sys.uptime(),
|
||||
shell: String::from("Unknown Shell"),
|
||||
terminal: String::from("Unknown Terminal"),
|
||||
cpu: String::from(sys.cpus()[0].brand()),
|
||||
gpu: String::from("Unknown GPU"),
|
||||
memory: String::from("Unknown memory"),
|
||||
icon: '?',
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user