Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated dependencies, fixed megabyte display, works with Win 11 again #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ Cargo.lock
# Added by cargo

/target
/.idea/**
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ publish = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
colored = "2.0.0"
whoami = "1.1.1"
sysinfo = { version = "0.23.2", default-features = false }
colored = "2.0.4"
whoami = "1.4.1"
sysinfo = { version = "0.29.10", default-features = false }
32 changes: 27 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use colored::*;
use std::string::ToString;
use sysinfo::{System, SystemExt, RefreshKind, ProcessorExt};
use sysinfo::{System, SystemExt, RefreshKind, CpuExt};

const FERRIS_ART: &[&str] = &[
" ",
Expand All @@ -21,6 +21,15 @@ const FERRIS_ART: &[&str] = &[
" ",
];

const BYTES_TO_MEGABYTES_FACTOR: u64 = 1024 * 1024;

/// Some values are hard to interpret when displayed as a numbers of bytes, so this function
/// converts a number of byte as number of megabytes.
fn bytes_to_megabytes(nob: u64) -> u64 {
nob / BYTES_TO_MEGABYTES_FACTOR

}

fn exc(exc: &str) -> Result<std::process::Output, std::io::Error> {
let mut exc = exc.split_whitespace();
let mut cmd = std::process::Command::new(exc.next().unwrap());
Expand Down Expand Up @@ -66,12 +75,14 @@ fn main() {
art = false;
}

let mut sys = System::new_with_specifics(RefreshKind::new().with_cpu());
let mut sys = System::new_with_specifics(RefreshKind::new());
sys.refresh_all();
let kernel = sys.kernel_version().unwrap_or_else(|| "Unknown".into());
let total_ram = sys.total_memory();
let used_ram = sys.used_memory();
let cpu = sys.processors()[0].brand();

let total_ram = bytes_to_megabytes(sys.total_memory());
let used_ram = bytes_to_megabytes(sys.used_memory());

let cpu = sys.cpus()[0].brand();

let rustc_ver = get_ver("rustc -V");
let cargo_ver = get_ver("cargo -V");
Expand Down Expand Up @@ -145,3 +156,14 @@ fn main() {
],
);
}

#[cfg(test)]
mod tests {
use crate::bytes_to_megabytes;

#[test]
fn bytes_to_megabytes_test() {
let bytes = 32 * 1024 * 1024;
assert_eq!(bytes_to_megabytes(bytes), 32);
}
}